TOPIC

Wrong answer (100%)

Nicole Gillian asked 11 months ago

int n, m, i, soma=0;

  while (n>0 || m>0){
      scanf("%d", &n);
      scanf("%d", &m);
      if (n<=0||m<=0){
          break;
      }
      else if (n<m){
          for(i=n;i<=m;i++){
              printf("%d ", i);**
              soma+=i;
          }
          printf("Sum=%d\n", soma);
          soma=0;
      }
      else if (n>m){
          for(i=m;i<=n;i++){
              printf("%d ", i);
              soma+=i;
          }
          printf("Sum=%d\n", soma);
          soma=0;
      }
  }

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

  • Farhan Faiyaz replied 6 months ago

    int n, m, i, soma=0;
    
    ```while (n>0 || m>0)
    
    here int n,m; // n and  m are unassigned number. when you are checking the while loop n>0 || m>0 it compares with garbage value which can be negetive or positive.

    while(scanf("%d %d", &m,&n)!=EOF) if(a>0 && b>0) .........

    you can try like this