The statement says:
Write a program that reads multiple integers and positives and calculates and shows the largest and smallest numbers read. Consider that: To terminate data entry, zero must be entered. For negative values, a message should be sent stating that the value is negative. Negative or zero values will not be entered in the calculations.
So far I have done the following:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int quant_val=0,numero=1,soma=0,maior=0,menor=0;
printf("Insira o numero positivo: ");
scanf("%d",&numero);
while(numero>=1 || numero!=0){
quant_val++;
soma=soma+numero;
if(numero<0){
printf("Valor e negativo!\n");
}
if(numero==1){
maior=numero;
menor=numero;
}
if(numero>maior){
maior=numero;
}
if(numero<menor){
maior=numero;
}
printf("Insira o numero positivo: ");
scanf("%d",&numero);
}
printf("O numero maior e: %d\n",maior);
printf("O numero menor e: %d\n",menor);
printf("A soma dos numeros e: %d\n",soma);
system("pause");
return 0;
}
The problem is that I can not remove the negative numbers from the calculation.
Can anyone help me?