Author Topic: Turbo C Program for sum of factorial numbers  (Read 1666 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Turbo C Program for sum of factorial numbers
« on: March 16, 2012, 03:58:04 am »
Here is the Turbo C Program for sum of factorial numbers

Code:
//Source Code Listing


#include <stdio.h>
#include <math.h>

int Fact(int n) 
{ 
   if( n <= 1) 
      return 1; 
   return n * Fact(n - 1); 
}


void main()
{
   int i, n;
   int sum = 0;
   printf("Enter number: ");
   scanf("%d", &n);
   
   for(i = 1; i <= n; i++)
   {
      sum = sum + Fact(i);
      printf("\nTerm: %-5d Value = %-5d Sum = %-5d", i, Fact(i), sum);
   }
   printf("\n\n");
}

output:

Enter number: 5

Term: 1 Value = 1     Sum = 1
Term: 2 Value = 2     Sum = 3
Term: 3 Value = 6     Sum = 9
Term: 4 Value = 24    Sum = 33
Term: 5 Value = 120   Sum = 153

Press any key to continue . . .
« Last Edit: March 16, 2012, 04:05:14 am by kathir »

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1