TOPIC

Error - 10% why I dont understand

Defalt asked 1 year ago

int N=1,M=1; int sum=0; while((N!=0)&&(M!=0)){ sum=0; scanf("%d",&M); scanf("%d",&N); if((M==0)||(N==0)){ break; } if(M<N){ for(int i=M;i<=N;i++){ sum+=i; printf("%d ",i); } printf("Sum=%d\n",sum); }

if(N<M){
for(int i=N;i<=M;i++){
    sum+=i;
    printf("%d ",i);
}
printf("Sum=%d\n",sum);
}
if(N==M){
 sum=M;
    printf("%d ",M);
printf("Sum=%d\n",sum);
}

}

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

  • feodorv replied 1 year ago

    The last line of the file contains a number zero or negative, or both

    So

    if( M <= 0 || N <= 0 ) break;