Search This Blog

Thursday, October 13, 2011

Write a program to return factorial of a num as a long interger variable

 

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  long getfact(int n);
   4:  void main()
   5:  {
   6:  int k;
   7:  long f;
   8:  printf("Enter the num: ");
   9:  scanf("%d",&k);
  10:  f=getfact(k);
  11:  printf("Factorial of %d is:%ld\n",k,f);
  12:  getch();
  13:  }
  14:  long getfact(int n)
  15:  {
  16:  long fact=1;
  17:  int i;
  18:  for(i=2;i<=n;i++)
  19:  fact=fact*i;
  20:  return(fact);
  21:  }

No comments:

Post a Comment