This C program evaluates the expression
1 + 2!/3! + 3!/4! + 4!/5! + ... n!/(n+1)!
The program evaluates the expression for the value of n.
Notice in this program that, in the function part, we have skipped the initialization in the for loop. This is because we have initialized the variable earlier.
1 + 2!/3! + 3!/4! + 4!/5! + ... n!/(n+1)!
The program evaluates the expression for the value of n.
Notice in this program that, in the function part, we have skipped the initialization in the for loop. This is because we have initialized the variable earlier.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int facto(int f) | |
{ | |
int fact = 1; | |
for(;f>0;f--) | |
{ | |
fact=fact*f; | |
} | |
return fact; | |
} | |
int main() | |
{ | |
int n,i; | |
float ans = 1,term; | |
printf("Enter the value of n: "); | |
scanf("%d",&n); | |
for(i=2;i <= n;i++) | |
{ | |
term = (float)n/facto(n + 1); | |
ans = ans + term; | |
} | |
printf("The value is %f ",ans); | |
getch(); | |
return(0); | |
} |
Comments
Post a Comment