Function Main
Declare Integer n, count
Declare Real x, term, sum, accuracy
Output "Enter value of x: "
Input x
Assign accuracy = 0.0001
Assign n = 1
Assign term = 1
Assign sum = 1
Assign count = 1
While n <= 100
Assign term = term * x / n
Assign sum = sum + term
Assign count = count + 1
If term < accuracy
Assign n = 999
Else
Assign n = n + 1
End
End
Output "Terms: " & count & " and sum is " & sum
End
#include <stdio.h>
int main() {
int n, count;
double x, term, sum, accuracy;
printf("Enter value of x:");
scanf("%lf", &x);
accuracy = 0.0001;
n = 1;
term = 1;
sum = 1;
count = 1;
while (n <= 100) {
term = term * x / n;
sum = sum + term;
count = count + 1;
if (term < accuracy) {
n = 999;
} else {
n = n + 1;
}
}
printf("Terms:%d and sum is %lf\n", count, sum);
return 0;
}
I am Md. Anisur Rahman. I have completed Cyber Security for MSCSE at United International University in 2022.I have completed PGDIT from IIT, Jahangirnagar University in 2020. I'm a Head of IT at Programming24 School.
View all posts by Md. Anisur Rahman