Miti059

1.find sum of even numbers between 1 to n

Jun 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.17 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 numbers 1 to n is %d",sum);
  13. return 0;
  14.  
  15. }
Add Comment
Please, Sign In to add comment