# C Program to Find Sum of All Even Numbers Between 1 to N using For Loop

• Write a C program to find sum of all even numbers between 1 to N using for loop.
• Wap in C to print sum of all even numbers between 1 to 100 using for loop.

Required Knowledge

• C printf and scanf functions
• For loop in C

### C program to find sum of all even numbers between 1 to N using for loop

#include <stdio.h>

int main() {
int counter, N, sum = 0;
/*
* Take a positive number as input form user
*/
printf("Enter a Positive Number\n");
scanf("%d", &N);

for(counter = 1; counter <= N; counter++) {
/* Even numbers are divisible by 2 */
if(counter%2 == 0) {
/* counter is even, add it to sum */
sum = sum + counter;
}
}
printf("Sum of all Even numbers between 1 to %d is %d", N, sum);

return 0;
}

Output

Enter a Positive Number
9
Sum of all Even numbers between 1 to 9 is 20