Advertisement
afrinahoque

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

Jun 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.27 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n, i=1, Sum=0;
  5.     printf("Enter the number:");
  6.     scanf("%d", &n);
  7.     while (i<=n)
  8.     {
  9.         if(i%2==0)
  10.             Sum=Sum+i;
  11.             i++;
  12.     }
  13.     printf("Sum of all even numbers=%d", Sum);
  14.     return 0;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement