Thursday, 28 May 2015

Factorial of number(non-recursive)


Factorial of a Number is as shown below

E.x. 2! = 2*1 ; 3! = 3*2*1 ; 4! = 4*3*2*1 ; 0! = 1

//Factorial of number(non-recursive)

#include<stdio.h>
int main()
{
   int k=1,num;
   printf("enter a number:");
   scanf("%d",&num);
   
   for(int i=num-1;i>=1;i--)
     num*=i;
 
     printf("factorial of number is : %d",num);
}



No comments:

Post a Comment