Chinese, asked by rajeshshriwastav23, 9 months ago

cuuu.
://Program to find factorial of a number
#include<iostream.h>
#include<conio.h>
void main()
int fact, number;
clrscr();
fact - 1;
cout << "Enter the number" <<endl;
cin>>number;
for (i=1;i<-number; i++)​

Answers

Answered by ItzDazzingBoy
64

*

* @author: BeginnersBook.com

* @description: User would enter the 10 elements

* and the program will store them into an array and

* will display the sum of them.

*/

import java.util.Scanner;

class FactorialDemo{

public static void main(String args[]){

//Scanner object for capturing the user input

Scanner scanner = new Scanner(System.in);

System.out.println("Enter the number:");

//Stored the entered value in variable

int num = scanner.nextInt();

//Called the user defined function fact

int factorial = fact(num);

System.out.println("Factorial of entered number is: "+factorial);

}

static int fact(int n)

{

int output;

if(n==1){

return 1;

}

//Recursion: Function calling itself!!

output = fact(n-1)* n;

return output;

}

}

Output:

Enter the number:

5

Factorial of entered number is: 120

Similar questions