TÓPICO

wrong answer but why

Unknown11. perguntou 1 year ago

include

int main() { int n,i,s=0,p=0,t=0; scanf("%d",&n); int x[n]; for(i=0;i<n;i++) { scanf("%d",&x[i]); if(x[i]<x[i-1]) { s=x[i]; p=i; t++; } } if(t==0) { s=x[0]; p=0; } printf("Menor valor: %d\n",s); printf("Posicao: %d\n",p); return 0; }

Lembre de não publicar soluções. Sua publicação pode ser revisada por nossos moderadores.

  • feodorv respondido 1 year ago

    for(i=0;i<n;i++) { scanf("%d",&x[i]); if(x[i]<x[i-1])

    When i is 0 you have x[-1] here and this can result in RTE.

    As for WA you can consider the following input:

    3
    1 3 2

    Because x[2] < x[1] your code makes s=x[2]; p=2 which is WA.