Write a program to find the factorial of 7 using for loop and while loop fast it's urgent
Answers
Answer:
The given program is written in Java.
1. Using for loop.
public class Factorial{
public static void main(String args[]) {
int a=7,f=1,i;
for(i=2;i<=a;i++)
f *= i;
System.out.println("Factorial of "+a+" is: "+f);
}
}
2. Using while loop.
public class Factorial{
public static void main(String args[]) {
int a=7,f=1,i=2;
while(i<=a){
f *= i;
i++;
}
System.out.println("Factorial of "+a+" is: "+f);
}
}
Refer to the attachment for output.
•••♪
Answer:
#Python códe to print the factorial of 7 in for and while loop
f=1
print("factorial of 7 in for loop ")
for I in range(1,7+1):
f * =I
print("output:",f)
print("Factorial of 7 in while loop ")
while(I<7):
f * =I
I+=1
print("output:",f)