Saturday, 31 August 2013

Write a program to find the factorial value of any number entered through the keyboard using for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,fact=1;/*Intialization of factorial , if u dont  then garbaage value is add in the value of Factorial*/
printf("Enter a number to calculate its factorial");
scanf("%d",&n);
for (i=1;i<=n;i++)/*if i will be great the n,so the loop will terminate*/
fact=fact*i;
printf("factorial of %d=%d",n,fact);
getch();
}

No comments:

Post a Comment