hi✌️✌️
1)WAP to enter a number and print factorial of that number.
Answers
Answer:
#include<stdio.h>
int main(){
int i,f=1,num;
printf("Enter a number: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
f=f*i;
printf("Factorial of %d is: %d",num,f);
return 0;
}
Result:
Enter a number: For example 8
Factorial of 8 is: 40320
#Capricorn Answers
Answer:-
➣
• Factorial Program in JAVA for n numbers:-
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
java.util.Scanner;
class Factorial
{
main (String args [ ])
{
int n, c, f = 1;
System.out.println("Enter a number to Calculate the Factorial");
Scanner in = new Scanner (System.in);
n= in.nextInt( );
(n<0)
System.out.println("Number should be non-negative");
{
(c =1; c <= n; c++)
f = f*c;
System.out.println("Factorial of "+n+" is = " +f);
}
}
}
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
• Factorial Program in PYTHON for n numbers:-
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
number = int(input("Enter a number to Calculate the Factorial:"))
fact = 1
for i in range (1, number + 1):
fact = fact*i
print("The Factorial of %d = %d %(number,fact))
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬