‘C’ program to accept real number x and integer n and calculate the sum of first n terms of the series x+ x/3!+ x/5!+ x/7!+…
C File =>
/* Write a ‘C’ program to accept real number x and integer n and calculate
the sum of first n terms of the series
x+ x/3!+ x/5!+ x/7!+… */
#include<stdio.h>
int main()
{
int x,n,i;
float sum=0;
printf("\n Enter value of x : ");
scanf("%d",&x);
printf("\n Enter value of n : ");
scanf("%d",&n);
printf("\n\n Sum of series x+x/3!+x/5!...\n");
// defining function to compute factorial
int fact(int n)
{
if(n==1)
return 1;
else
return (n*fact(n-1));
}
// computing sum of series
for(i=1;i<=n;i=i+3)
sum=sum+x/fact(i);
printf("\n %f",sum);
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.