Sum of ODD number from Given Range
#include <stdio.h>
void main()
{
int index, begno, endno, sum = 0;
printf("Program for sum of odd numbers in the given range");
printf("Enter Beg. No.: ");
scanf("%d", &begno);
printf("Enter End. No.: ");
scanf("%d", &endno);
index = begno;
if( (begno % 2) == 0)
index = begno + 1;
for(; index <= endno; index += 2)
{
sum = sum + index;
}
printf("The sum of odd numbers between %d and %d is: %d", begno, endno, sum);
}
#include
ReplyDeletemain()
{
int i,n,sum=0;
printf("Enter the range:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2 !=0)
sum+=i;
}
printf("the sum of odd number is:%d\n",sum);
}
#include
ReplyDeletemain()
{
int i,j,n,sum=0;
printf("Enter start num :\n");
scanf("%d",&j);
printf("\nEnter end num :\n");
scanf("%d",&n);
for(i=j;i<=n;i++)
{
if(i%2!=0)
{
sum+=i;
}
}
printf("Sum of odd num from given range is :%d",sum);
}