TOPIC

Output is ok.

Abdullah48 asked 3 years ago

My code is producing correct output. I can't understand what went wrong. this is my code

include

int main(){ int a,n,s; scanf("%d",&a); do{ scanf("%d",&n); }while(n<=0); while(n--){ s=s+a; a++; } printf("%d\n",s); }

This topic was solved and cannot recieve new replies.

  • alexis__t replied 3 years ago

    try:

    int s=0
    for(int i=0; i<n; i++)
      s+=(a+i);
    printf(...)
  • Abdullah48 replied 3 years ago

    Thank you so much ALEXIS TOIGO. After declaring s=0 the program worked!!!!