Saturday, 2 April 2016


 Q. Write an algorithm to calculate factorial of a +ve number within range 1-10.

#include<stdio.h>
#include<conio.h>

int n,x,f=1;
void main()
{
printf("Enter the number:");
scanf("%d",&n);
if((n>0)&&(n<=10)) 
{
for(x=1 ; x<=n; x++)
f=f*x; 
printf("Factorial=%d",f);
}
else 
printf("Number is not in a given Range");
getch();
}

No comments:

Post a Comment