Subscribe

RSS Feed (xml)

Wednesday, February 17, 2010

Write a C program to find the exponential series of 1+x+x2/2!+x3/3!+.......+xn/n!

#include< math.h>
void main( )
{
int x, n, fact, i, j;
float sum=1;
clrscr( );
printf("Enter the 'x' value:");
scanf("%d",&x);
printf("\nEnter the 'n' value:");
scanf("%d",&n);
for(i=1; i< =n ; i++)
{
fact=1;
for( j=i ; j >=1; j--)
fact=fact*j;

sum=sum+(pow(x,i )/ fact);
}
printf("\nSum of the series : %f ",sum);
getch( );
}

Note:- If any errors,, plz mail to me.

Sunday, February 14, 2010

Write a C program to display all Even numbers upto the given range.

#include< stdio.h>
#include< conio.h>
int main( )
{
int x, r;
clrscr( );
printf("Enter the range:");
scanf("%d",&r);
for(x=1; x <=r; x++)
{
if(x%2==0)
printf("%5d", x);
}
getch( );
return 0;
}

Output:-
Enter the range:10
2 4 6 8 10

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;
}

Write a C program to compute the sum of the terms 1+2+3+.....upto N terms

#include< stdio.h>
#include< conio.h>
int main()
{
int n,i,sum=0;
clrscr();
printf("Enter the 'n' value:");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
sum=sum+i;
}
printf("\nSum of the 'n' terms: %d",sum);
getch();
return 0;
}