/*
Name: WAP to find factorial of a given number without using recursion
Author: Parveen Malik
Date: 23/09/11 10:21
*/
#include <stdio.h>
#include <conio.h>
long factorial(int);
void main(void)
{
int num;
long fact=1;
printf("Enter a number to calculate its factorial : ");
scanf("%d",&num);
printf("%d = %ld \n",num,factorial(num));
getch();
}
long factorial(int n)
{
int count;
long result=1;
for(count=1;count<=n;count++)
result=result*count;
return (result);
}
OUTPUT:
0 comments:
Post a Comment