Algorithm:
Input:
1. n
Output:
1. fact
Method:
1.start
2.read n
3.write n
4.def fact(n) #calling function
5.stop
#called function before the main program
def fact(n)
f=1
for i in range(1,n+1,1)
begin
f=f*i
end
write"The factorial of given number is:",f
#program
def fact(n):
f=1
for i in range(1,n+1,1):
f=f*i
print("The factorial of given number is:",f)
#main program
n=int(input("Enter n number"))
print("n=",n)
fact(n)
Example:
Enter n number 4 n= 4 The factorial of given number is: 24
No comments:
Post a Comment