Question 11: Write a menu driven program to generate the sum of the following series as per the choice entered by the user. 1) x2 /3! – x 3 /4! + x4 /5! - ………xn / (n +1)! 2) 99, 80, 63, 48…… up to 10 terms
ANSWER IT FAST
Answers
I don't clear the question
menu-driven program to generate the sum of the following series
Explanation:
For part 1:
#include<stdio.h>
long double first_series(long int x, long int n){
long double ans=0;
int sign = 1;
long int num = x*x, den = 3*2, temp = 3;
for(int i=0; i<n; i++){
ans = ans + sign*(double)num/den;
num*=x;
den = den*(++temp);
sign*=(-1);
// printf("%LF %ld\n", ans, den);
}
return ans;
}
For part 2:
long int second_series(long int n){
long int ans = 0, dec=19;
long int start = 99;
for(int i=0; i<n; i++){
ans+=start;
// printf("%ld ", start);
start-=dec;
dec-=2;
}
return ans;
}
int main(){
long int choice , n, x;
printf("Press 1: To find sum of the series x2/3!-x3/4!+x4/5!-...upto n terms \n");
printf("Press 2: To find sum of the series 99, 80, 63, 48,...upto n terms \n\n");
printf("Enter Choice: ");
scanf("%ld", &choice);
switch(choice){
case 1:{
printf("Enter n: ");
scanf("%ld", &n);
printf("Enter x: ");
scanf("%ld", &x);
printf("Sum of series x2/3!-x3/4!+x4/5!-...upto %ld terms and x = %ld is:\n%Lf",n,x,first_series(x,n));
break;
}
case 2:{
printf("Enter n: ");
scanf("%ld", &n);
printf("Sum of series 99, 80, 63, 48,...upto %ld terms is:\n%ld",n,second_series(n));
break;
}
default:{
printf("Wrong Input\n");
}
}
printf("\n");
return 0;
}
hence, this is the required program