// Program
# include <stdio.h>
void main()
{
int n,fact=1,i;
printf("Enter any positive integer value : ");
scanf("%d",&n);
if(n>0)
{
for(i=1;i<=n;i++)
{
fact = fact*i;
}
printf("Factorial : %d",fact);
}
else
{
printf("Please enter the positive value > 0");
}
}
// Factorial of a Number using Recursion
#include<stdio.h>
int main()
{
int m,FACT(int);
printf("Enter any +ve integer value : \n");
scanf("%d",&m);
if(m>=0)
{
printf("Factorial of %d is %d",m,FACT(m));
}
else
{
printf("Kindly enter +ve value");
}
return 0;
}
int FACT(int n)
{
if(n==0)
{
return (1);
}
else
{
return(n*FACT(n-1));
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.