Q12 Write a program to add first seven terms of the following series using a for loop:

Write a program to add first seven terms of the following series using a for loop:

Program: 104

Write a c program to add first seven terms of the following series using a for loop:

#include<stdio.h>
#include<conio.h>
int main()
{
    int i;
    float fact=1.0, res, n_res=0;

    //functionality
    //loop counter for 7 steps (1 to 8)
    for (i=1;i<8;i++)
    {
        //find factorial for 1 to 7
        fact = fact * i;

        //find the i/factof(i)
        res = i/fact;

        //add all the results
        n_res = n_res + res;
    }

    printf("%f", n_res);
}

Output:

2.718056

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.