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