Sum of 1 to n odd numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,sum=0,n;
clrscr();
printf("enter the number ");
scanf("%d",&n);
while(i<=n)
{
if(i%2!=0)
{
sum=sum+i;
}
i=i+1;
}
printf("sum of odd number=%d",sum);
getch();
}

No comments:

Post a Comment