Sunday 3 April 2011

write a program to find the sum of first n odd integers

/* write a program to add first seven series using for loop
Name: Mohammad Tahir
Date: 4 April 2011 */

#include
#include
void main()
{
int sum=0;
int i,n;
printf("Enter the term: ");
scanf("%d",&n);
for(i=1; i<=n; i=i+2)
{
sum=sum+i;
}
printf("the sum of odd numbers is %d",sum);
getch();
}

No comments:

Post a Comment