Advertisement
PROFESSOR_AIH

Summing Consecutive Integers

Apr 8th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int a,n,sum=0,count=0;
  5.     scanf("%d %d",&a,&n);
  6.     while(1)
  7.     {
  8.         if(n<=0)
  9.             scanf("%d",&n);
  10.         if(n>0)
  11.             break;
  12.         else
  13.             continue;
  14.     }
  15.     while(count!=n)
  16.     {
  17.         sum=sum+a;
  18.         count++;
  19.         a++;
  20.     }
  21.     printf("%d\n",sum);
  22.     return 0;
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement