Subscribe

RSS Feed (xml)

Tuesday, February 9, 2010

Write a program to compute the sum of the terms 1+3+5+7+9+--------- until the sum>500

#include< stdio.h>
#include< conio.h>
int main()
{
long int i,sum=0;
clrscr();
for(i=1; ;i++)
{
if(i%2!=0)
sum=sum+i;
if(sum>500)
break;
}
printf("\nSum of the 1+3+5+---- until the sum>500 is : %ld",sum);
getch( );
return 0;
}

1 comment: