RIFATKHAN1

sum of even numbers between 1 to n. - using while loop

Jun 23rd, 2019
324
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int num,i=2,sum=0;
  5.     scanf("%d",&num);
  6.  
  7.     while(i<=num)
  8.     {
  9.         sum=sum+i;
  10.         i=i+2;
  11.     }
  12.  
  13.     printf("sum of even numbers = %d",sum);
  14.     return 0;
  15. }
RAW Paste Data