TOPIC

o que pode estar errado?

tgoncalves19 asked 4 years ago

int x, soma = 0, cont = 0;

while(1){
    scanf("%d", &x);
    if(x == 0){
        break;
    }
    if(x % 2 == 0){
        while(cont != 5){
            soma += x;
            x += 2;
            cont++;
        }
        printf("%d\n",soma);
        cont = 0;
        soma = 0;
        x = 0;
    }
    if(x % 2 == 1){
        x++;
        while(cont != 5){
            soma += x;
            x += 2;
            cont++;
        }
        printf("%d\n",soma);
        cont = 0;
        soma = 0;
        x = 0;
    }
}   

This topic was solved and cannot recieve new replies.

  • feodorv replied 4 years ago

    You can try the following input:

    -2
    0

    Instead of

    if(x % 2 == 0)

    you can use

    if( (x & 1) == 0 )