Advertisement
PROFESSOR_AIH

Sum of Consecutive Even Numbers

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