Testing.

Sunday, 1 January 2017

C programming language: Factorial program in c without using recursion.

Example: 5!=5*4*3*2*1=120
--------------
#include<stdio.h>
#include<conio.h>

int factorial(int n)
{
int f=1,i;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}
void main()
{
int fact,n;
printf("\nEnter number:");
scanf("%d",&n);
fact=factorial(n);
printf("\nFactorial of %d is :%d ",n,fact);
getch();
}


No comments:

Post a Comment