Skip to content

Instantly share code, notes, and snippets.

@vittodevit
Created March 27, 2021 22:32
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 vittodevit/e569303ee04a01de030ed39ff0082426 to your computer and use it in GitHub Desktop.
Save vittodevit/e569303ee04a01de030ed39ff0082426 to your computer and use it in GitHub Desktop.
Conta tutti i numeri positivi e negativi dato l'input dell'utente.
#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