+ 4
What is code for factorial in java
coding used is loop
5 ответов
+ 4
Please go through this code...That will help you.
https://code.sololearn.com/c7tgNvlD6T12/?ref=app
+ 2
JavaScript
let num = Number(prompt("Enter a number"));
let fact = 1;
while(num) {
fact*=num;
num-=1;
}alert(fact);
+ 2
import java.util.Scanner;
class Factorial
{ public static void main(String[] args){
int no, factorial=1;
Scanner s=new Scanner(System.in); System.out.println("Enter Number :"); no=s.nextInt();
for(int i=1; i<=no; i++)
{
factorial=factorial*i;
}
System.out.println("Factorial is :" +factorial);
}
}
+ 2
import java.util.Scanner;
class fact
{
public static void main(String args())
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int factorial=1;
for(int i=1;i<=n;i++)
{
factorial=factorial*i;
}
System.out.println("Factorial of"+n+"is"+factorial);
}
}