TOPIC

Meu código está apresentado runtime error

sgomes13 asked 4 years ago

//Minha entrada "4" é a única que printa uma saída atípica, sendi a saída = "3". Ademais, as outras estão corretas, entretanto, //o código está apresentando runtime error;

int main(){

int i, x, j, y;

int ant = 0;

int prox = 1;

int res = 0;

for(i=1; i!=EOF; i++, ant = 0, prox = 1){

    scanf("%d %d", &x, &y);

    for(j=1; j<=x; j++){
        res=prox+ant;
        ant=prox;
        prox=res;

    }
    printf("%d\n", ant%y);
}

return 1;

}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 4 years ago

     i!=EOF

    What did you mean by it?

    The input consists of several test cases and ends with EOF

    It should be like this:

    while( scanf( "%d %d", &x &y) == 2 )
    {
      ...
    }

    or like this at the last end:

    while( scanf( "%d %d", &x, &y) != EOF )
    {
      ...
    }