Wednesday, February 23, 2011

Decision Making and Looping

The factorial of an integer m is the product of consecutive integers from 1 to m. That is,
factorial m = m! = m*(m-1)*.....*1.
Write a program that computes and prints a table of factroials for any given m.

#include <stdio.h>
void main()
{
int x,fact=1,i;
clrscr();
printf("Enter a number to get factorial:");
scanf("%d",&x);
for(i=x;i>=1;i--)
{
fact=fact*i;
}
printf("\nFactorial = %d",fact);
getch();
}

No comments:

Post a Comment