Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

Dr. A.P.J. Abdul Kalam Technical University, Lucknow

KCS151 / KCS251 Programming for Problem Solving - Using C Language


Lab Exercises


9. Write a program to generate the sum of series 1!+2!+3!+--------------n!


/*
 File: Prgrm09.c
 Author: Aditya Saini
 Date: Jan 16, 2021
 Description: Program to generate the sum of series 1!+2!+3!+--------------n!
*/

#include <stdio.h>

int main (void)
{
     int n;
     long int fact;
     long int sum;
     int i, j;

     //Input number of terms
     printf ("Input number of terms: ");
     scanf ("%d", &n);
     printf (Series: );

     //Calculate the sum of series
     sum = 0;
     fact = 1;
     for (i = 1; i <= n; i++)
     {
          fact = 1;
          for (j = 1; j <= i; j++)
               fact = fact * j;
          sum = sum + fact;
     }

     //Print result
     printf ("Sum of Series: %ld", sum);

     return 0;
};

Output

Input number of terms: 10
Sum of Series: 4037913



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib