C Program To Calculate Sum of Even Numbers
Learn How To Calculate Sum of Even Numbers in C Programming Language. Find Addition of Even Numbers from 1 To N using For Loop in C Programming. It is important that we should know How A For Loop Works before getting further with the C Program Code.
Also Read: C Program Code To Find Sum of Odd Numbers
Method 1: C Program To Calculate Sum of Even Numbers From 1 To N using For Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<stdio.h> int main() { int count, limit, sum = 0; printf("\nEnter Limit:\t"); scanf("%d", &limit); for(count = 1; count <= limit; count++) { if(count%2 == 0) { sum = sum + count; } } printf("\nSum of Even Numbers from 1 To %d:\t %d", limit, sum); printf("\n"); return 0; } |
Method 2: Find Sum of Even Integers in C Programming using While Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<stdio.h> int main() { int count = 1, limit, sum = 0; printf("\nEnter Limit:\t"); scanf("%d", &limit); while(count <= limit) { if(count%2 == 0) { sum = sum + count; } count++; } printf("\nSum of Even Numbers from 1 To %d:\t %d", limit, sum); printf("\n"); return 0; } |
Also Read: C Program Code To Check Even and Odd Numbers
Output

If you have any Compilation Errors or any doubts in this C Program To Calculate Sum of Even Numbers from 1 To N or you have any doubts, let us know about it in the Comment Section below.