Computer Science, asked by Anonymous, 2 months ago

WAP to take a number as input and find its factorial .
pls help me out ... don't spam​

Answers

Answered by Oreki
9

\textsf{\large \textbf{Factorial (n!)}}

  \text{It is the product of all positive numbers less than or equal to a given number.}\\\text{Denoted by the number followed by an exclamation symbol (!).}

\textsf{\large \textbf{Algorithm}}

  \text{\textemdash \:\: Accepting a number using the \textbf{Scanner} class.}\\\text{\textemdash \:\: Multiplying all positive integers less than or equal to the accepted number.}\\\text{\textemdash \:\: Printing the resulting integer.}

Attachments:
Answered by BrainlyProgrammer
16

Answer:

//Program to print the factorial of a number

package Programmer;

import java.util.*;

public class Fact{

public static void main (String ar[]){

Scanner sc=new Scanner (System.in);

System.out.print("Enter a number");

int n=sc.nextInt();

int f=1;

for(int i=1;i<=n;i++){

f *=i;

}

System.out.println("Factorial of "+n+" is "+f);

}

}

_____

Variable Description:-

  • f:- To calculate and store factorial of a number
  • n:- to accept number as Input from the user

_____

Explaination:-

  • The program accepts the number from the user and stores it in variable 'n'.
  • variable 'f' is initialized to 1
  • Then I loop is running from 1 to n
  • f gets multiplied with loop value(value of I)
  • loop works till it's value is less than or equal to value of variable 'n'
  • Finally loop terminates when condition is false(I<=n)
  • Factorial of a number gets printed

_____

•Output Attached

Attachments:
Similar questions