Search This Blog

Friday, October 7, 2011

Write a program to display factorial of a number

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

1 comment: