Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1

7\11\22
22 CSH 101

Introduction to problem solving

Learn how to use looping constructs using C

Write a program to find sum of series e ^ x


#include <stdio.h>
#include <math.h>
int main()
{
int num,terms;
printf("enter the number");
scanf("%d",&num);
printf("enter the terms");
scanf("%d",&terms);

int i=1;
float fact=1,expo=0;
float sum=1;

while(i<terms)
{

fact = fact*i;

expo = pow(num,i);

sum += expo/fact;

i++;
}
printf("the sum of series e^x is %.1f",sum);

}
No error

We use integer i from 1 till no of terms inputted by user and run a loop with it and we calculate answer in
two parts where one is used for factorial and one for power calculation and at end we add it to sum and
sum keeps on adding new value till i reaches 1 less than terms and it exists because first term is 1 which
is added already

You might also like