Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //C program to find sum of even numbers between 1 to n. - using while loop
- #include<stdio.h>
- int main(){
- int i=1,n,sum=0;
- scanf("%d",&n);
- while(i<=n){
- if(i%2==0){sum+=i;}
- i++;
- }
- printf("Sum of even numbers between 1 to %d =%d\n",n,sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment