The basic C-code to find the factorial of a digit which is taken by user input.
Code for the program is like that ::
#include<stdio.h>
int main()
{
int i,fact=1,n;
printf("Enter the no:: \n");
scanf("%d",&n);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("factorial value of %d = %d",n,fact");
getch();
return 0;
}
NOW WE WILL FIND FACTORIAL OF A NUMBER USING RECURSION IN C PROGRAM
The code is like that
int fact(int );
int main()
{
int n,a;
printf("Enter The No :: \n");
scanf("%d",&n);
a=fact(n);
printf("factorial value of %d = %d",n,a);
getch();
return 0;
}
//here is the function
int fact(int a)
{
if(a==0)
{
return 1;
}
else
{
return a*fact(a-1);
}
}
The output will be like ::
No comments:
Post a Comment