C Program To Print Sum of Odd Numbers Between 1 To N

In this article, we are going to write a c program to print sum of odd numbers between 1 to n

We will make this program in the following way -:

  • C Program To Print Sum of Odd Numbers Between 1 To N
  • C Program To Print Sum of Odd Numbers Between 1 To 10
  • C Program To Print Sum of Odd Numbers Between 1 To 100

To make this program, we will use the following concept given below. If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given below.

Now without wasting time let’s start programming.

C Program To Print Sum of Odd Numbers Between 1 To N

C Program To Print Sum of Odd Numbers Between 1 To N

Algorithm

  • Program Start
  • Declare Variable
  • check condition
  • print result according to condition
  • Program End

Program

//C Program To Print Sum of Odd Numbers Between 1 To N Using For Loop

#include<stdio.h>

void main()
{
    int i,sum = 0,N;

    printf("Enter the Number : ");
    scanf("%d",&N);

    for(i=1;i<=N;i++)
    {
        if(i%2!=0)
        {
            sum = sum+i;
        }
    }

    printf("Sum of odd numbers between 1 to %d : %d",N,sum);

}

Output

Enter the Number : 5

Sum of odd numbers between 1 to 5 : 9

C Program To Print Sum of Odd Numbers Between 1 To 10

Program

//C Program To Print Sum of Odd Numbers Between 1 To 10

#include<stdio.h>
void main()
{
    int i,sum = 0;

    for(i=1;i<=10;i++)
    {
        if(i%2!=0)
        {
            sum = sum+i;
        }
    }

    printf("Sum of 1 to 10 odd numbers : %d",sum);

}

Output

Sum of 1 to 10 odd numbers : 25

C Program To Print Sum of Odd Numbers Between 1 To 100

Program

//C Program To Print Sum of Odd Numbers Between 1 To 100

#include<stdio.h>
void main()
{
    int i,sum = 0;

    for(i=1;i<=100;i++)
    {
        if(i%2!=0)
        {
            sum = sum+i;
        }
    }

    printf("Sum of 1 to 100 odd numbers : %d",sum);

}

Output

Sum of 1 to 100 odd numbers : 2500

Conclusion

So friends, in this article, we have written a c program to print sum of odd numbers between 1 to n in this way.

  • C Program To Print Sum of Odd Numbers Between 1 To N
  • C Program To Print Sum of Odd Numbers Between 1 To 10
  • C Program To Print Sum of Odd Numbers Between 1 To 100

If you have difficulty to understanding any program or have any doubts or questions, then tell me in the comment below.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Comment