Calculate Sum of Odd Numbers C Program

By | December 13, 2015

C Program To Calculate Sum of Odd Numbers

Learn How To Calculate Sum of Odd Numbers in C Programming Language. Find Addition of Odd 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 To Find Sum of Even Numbers

Method 1: C Program To Calculate Sum of Odd Numbers From 1 To N using For Loop

#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 Odd Numbers from 1 To %d:\t %d", limit, sum);
      printf("\n");
      return 0;
}

Method 2: Find Sum of Odd Integers in C Programming using While Loop

#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 Odd Numbers from 1 To %d:\t %d", limit, sum);
      printf("\n");
      return 0;
}

Also Read: C Program To Check Even and Odd Numbers

 

Output

Calculate Sum of Odd Numbers in C Programming

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

Let's Discuss