Prepare a program to request 10 numbers. You must display the amount of negative, positive and zeros typed

Asked

Viewed 35 times

-1

I am trying to create a program in C which asks for 10 numbers. You must display the amount of negative, positive and typed zeros. I’ve tried it here but it’s not working. Reading from scratch is incorrect, and asking for 11 variables instead of 10. Would you like to know what’s wrong? Yeah, I can’t figure it out

#include<stdio.h>
main(){
    int z,i;
    int x = 0;
    int y = 0;
    int h = 0;
    for(i=0;i<=10;i++){
    
    printf("digite o numero:");
    scanf("%d",&x);
    if (x<0){
        ++y;    
    }  if(x>0);{
        ++z;
    
    }  if (x % 10 == 0);{
     ++h;
    }
}

    printf("\n no total foram\n %i numeros positivos\n %i negativos \n %i 0 digitados.",z,y,h);
    
    return 0;
    
}

1 answer

-1

A cycle For i up to N starting from i= 0 has a total of (N + 1) repetitions. To test place a printf with i value in the loop block, which will contain 0,.. ,10 totaling 11 cycles.

The second and third decision shall have (;) at the end of the judgment

if(x>0); <••••; this characterized null decision, regardless of the boolean value of the expression the block below is executed.

if (x % 10 == 0); <•••• here idem, the block below runs because it is independent of the decision.

#1 In the programming This is a situation where ELSE is used, because the value of x can only be 1 of 3 situations.

if( x < 0 ){ ++y; } Else if( x > 0 ){ ++z; } Else { ++h; // x == 0 }

I do not understand, if (x % 10 == 0), how to decide whether the number is divisible integer by 10 is part of the answer, but the only flaw I found in the sentence is outside the expression o (;) after the parenthesis.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.