TOPIC

Output is ok.

Abdullah asked 1 year 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.

  • Aléxis Toigo replied 1 year ago

    try:

    int s=0
    for(int i=0; i<n; i++)
      s+=(a+i);
    printf(...)
  • Abdullah replied 1 year ago

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