Write a program using following equation : 1+ 2/2!+3 /3!+4 /4!+⋯
Program:
#include<stdio.h>
#include<math.h>
main()
{
int n, i;
float x,sum=0,y;
printf("Enter N = ");
scanf("%d", &n);
printf("Enter X = ");
scanf("%f", &x);
y=(x-1)/x;
for(i=2; i<=n; i++)
{
sum=sum+(pow(y,i)*.5);
}
printf("Sum=%f", sum+y);
}
Program:
#include<stdio.h>
#include<math.h>
main()
{
int n, i;
float x,sum=0,y;
printf("Enter N = ");
scanf("%d", &n);
printf("Enter X = ");
scanf("%f", &x);
y=(x-1)/x;
for(i=2; i<=n; i++)
{
sum=sum+(pow(y,i)*.5);
}
printf("Sum=%f", sum+y);
}