yoyo106

Sum of even numbers between x and y

Apr 23rd, 2018
89
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. #include <stdlib.h>
  3.  
  4. void main()
  5. {
  6. int i,x,y,sum=0;
  7. printf("Enter first value: ");
  8. scanf("%d",&x);
  9. printf("Enter second value: ");
  10. scanf("%d",&y);
  11. for (i=x;i<=y;i++)
  12. {
  13.     if(i%2==0)
  14.         sum=sum+i;
  15. }
  16.     printf("Sum is: %d",sum);
  17. }
Add Comment
Please, Sign In to add comment