Created
March 27, 2021 22:32
-
-
Save vittodevit/e569303ee04a01de030ed39ff0082426 to your computer and use it in GitHub Desktop.
Conta tutti i numeri positivi e negativi dato l'input dell'utente.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
int quantita; | |
printf("Inserisci quantità valori: "); | |
scanf("%d", &quantita); | |
int valori[quantita]; | |
int i = 1; | |
do{ | |
printf("Inserisci valore n%d:", i); | |
int newvals; | |
scanf("%d", &newvals); | |
if(newvals == 0){ | |
printf("Attenzione! Lo zero non verrà conteggiato!"); | |
} | |
valori[i-1] = newvals; | |
i++; | |
}while(i <= quantita); | |
int pos, neg = 0; | |
for(i = 0; i < quantita; i++){ | |
if(valori[i] > 0){ | |
pos+=1; | |
}else{ | |
neg+=1; | |
} | |
} | |
printf("I numeri positivi sono %d e quelli negativi sono %d!\n", pos, neg); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment