C Programming Code Examples C > For Loops and While Loops Code Examples Program to find sum of even numbers in given range Program to find sum of even numbers in given range Write a C program to input number from user and find sum of all even numbers between 1 to n. How to find sum of even numbers in a given range using loop in C programming. Logic to find sum of even numbers in a given range in C program. Input upper limit to find sum of even number. Store it in some variable say N. Initialize another variable to store sum with 0 say sum = 0. To find sum of even numbers we need to iterate through even numbers from 1 to n. Initialize a loop from 2 to N and increment 2 on each iteration. The loop structure should look like for(j=2; j<=N; j+=2). Inside the loop body add previous value of sum with j i.e. sum = sum + j. After loop print final value of sum. #include <stdio.h> int main() { int j, start, end, sum=0; /* Input lower and upper limit from user */ printf("Enter lower limit: "); scanf("%d", &start); printf("Enter upper limit: "); scanf("%d", &end); /* If start is not even then make it even */ if(start%2!=0) { start++; } for(j=start; j<=end; j+=2) { /* Add current even number to sum */ sum += j; } printf("Sum of all even number between %d to %d = %d", start, end, sum); return 0; }