Tuesday 20 November 2012

c program factorial number using function.


Take two for loop .first for loop for one to last .
till we want to factorial and second will calculate factorial of each number.
factorial means multiplication of numbers.
example
factorial of 5 is 5*4*3*2*1=120.
so factorial of 5 is 120.
same for 6 is 6*5*4*3*2*1=720.



#include<stdio.h>
#include<conio.h>
long int fact( int*);
void main()
{
  int n;
  clrscr();
  printf("enter the value \n");
  scanf("%d",&n) ;
  printf("result=%ld",fact(&n)) ;
  getch();
  }

 long int fact(int* a)
 {
 long int f=1,sum=0;  //initialization of sum=0 and variable f =1.
 int i,j;
 for(i=1;i<=*a;i++) //execution of for loop
 {
  for(j=1;j<=i;j++) // second for loop
  {
  f=f*i;
  }
  f=i/f;
  sum=sum+f;
  }
  return sum; // will return the factorial of given number.
  }


programming examples for  factorial number  using function
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: