Skip to content

Instantly share code, notes, and snippets.

@csr
Created November 12, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csr/88595c8106d979d2a732 to your computer and use it in GitHub Desktop.
Save csr/88595c8106d979d2a732 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int acquisisciNumeroCompresoTraValori(int min, int max) {
int inserimento;
printf("Inserisci un numero compreso tra %d e %d: ", min, max);
scanf("%d", &inserimento);
while ((inserimento < min) || (inserimento > max)) {
printf("Inserimento invalido! Riprova: ");
scanf("%d", &inserimento);
}
return inserimento;
}
int moltiplicaSommaQuattro(int somma) {
return somma*4;
}
int sommaElementiVettore(int vettore[], int lunghezzaVettore) {
int somma = 0;
for (int i = 0; i< lunghezzaVettore; i++) {
vettore[i] = 0;
}
return somma;
}
void stampaElementiVettore(int vettore[], int lunghezzaArray) {
for (int i = 0; i< lunghezzaArray; i++) {
printf("Alla posizione %d c'e' elemento %d.\n", i, vettore[i]);
}
}
void azzeramentoElementiVettore(int vettore[], int lunghezzaArray) {
for (int i = 0; i< lunghezzaArray; i++) {
vettore[i] = 0;
}
}
void mostraMenu(int numeri[], int lunghezza) {
printf("Inserisci 1 per azzerare, 2 per stampare, 3 per sommare, 4 per moltiplicare somma: ");
int scelta = acquisisciNumeroCompresoTraValori(1, 4);
switch (scelta) {
case 1:
azzeramentoElementiVettore(numeri, lunghezza);
case 2:
stampaElementiVettore(numeri, lunghezza);
case 3:
sommaElementiVettore(numeri, lunghezza);
case 4:
printf("%d", moltiplicaSommaQuattro(sommaElementiVettore(numeri, lunghezza)));
}
}
int main() {
int numeri[] = {3, 4, 3, 339, 389, 8, 38};
int lunghezzaArray = 7;
while (1) {
mostraMenu(numeri, lunghezzaArray);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment