Page Rank Checker

Saturday 5 July 2014

Find Sum Of First 7 Terms Of Series Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to add first seven terms of the following series using a for loop:     
         1/1! + 2/2! + 3/3! + ............

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    float n1, n2, ans=0, n1_fact=1;
    for(n1=1;n1<=7;n1++)
    {
        n1_fact=1;
        for(n2=1;n2<=n1;n2++)
        {
            n1_fact=n1_fact*n2;
        }
        ans=ans+(n1/n1_fact);
    }
    printf("Answer is %f",ans);
    getch();
}