23.12.19

Factorial ( Recursion Method) program in c

#include<stdio.h>

#include<conio.h>

int fact(int n)
{

int f;

if(n==0)

return 1;
else

f=n*fact(n-1);

return f;
}




void main()
{
int n,f;

clrscr();

printf("\n Enter the value of n");

scanf("%d",&n);

f=fact(n);

printf("\n Factorial of %d is %d ",n.f);

getch();

}



OUTPUT
Enter the value of n 5
Factorial of 5 is 120


No comments:

Post a Comment

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...