Skip to content

Commit c0369ca

Browse files
Merge pull request #22 from vish-han/patch-1
factorial-by-loops.java added
2 parents 4986f7c + 0a18b33 commit c0369ca

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//Question: You have to make an algorithm to find factorial of a given number;
2+
3+
//factorial of n is n*(n-1)*.....*2*1;
4+
package com.company;
5+
6+
import java.util.Scanner;
7+
8+
public class Factorial {
9+
public Factorial() {
10+
}
11+
12+
public static void main(String[] args) {
13+
Scanner in = new Scanner(System.in);
14+
System.out.println("you want factorial of which number");
15+
16+
//input of given number
17+
int n = in.nextInt();
18+
int fact = 1;
19+
for(int i = n; 1 <= i; --i) {
20+
fact *= i;
21+
}
22+
23+
System.out.println("the factorial of " + n + " is " + fact);
24+
}
25+
}

0 commit comments

Comments
 (0)