Mim527

1.sum of even numbers 1 to n.

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