Q:

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

belongs to collection: Basic C Programming Examples

0

you have to 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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program to Find Average of Three Numbers... >>
<< C Program to Find the Sum of first 10 Natural Numb...