Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi there, I need help in this coding. Any idea how to add a counter to count the number of times the program runs to
Hi there, I need help in this coding. Any idea how to add a counter to count the number of times the program runs to get it's GCD?
This program is a GCD algorithm.
a = int(input("Enter first number : "))
b= int( input("Enter second number : "))
def RecursionGCD(a,b,count=0):
if(b==0): #base
c=A%B;
A=B;
B=c;
count+=1;
return a #case
else:
return RecursionGCD(b,a%b) #recursion
a = int(input("Enter first number : "))
b= int( input("Enter second number : "))
# prints results
print ("The gcd of the 2 numbers is : ",end="")
print (RecursionGCD(a,b))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started