Srite a program to evaluate the Hcf of two positive integers
Answers
Answered by
2
Input two numbers from user. Store them in some variable say num1 and num2 . Declare and initialize a variable to hold hcf i.e. hcf = 1 . ... Inside the loop check if i is a factor of two numbers i.e. if i exactly divides the given two numbers num1 and num2 then set i as HCF i.e. hcf = i .
Answered by
2
Answer:
Input two numbers from user. Store them in some variable say num1 and num2.
Declare and initialize a variable to hold hcf i.e. hcf = 1.
Find minimum between the given two numbers. Store the result in some variable say min = (num1<num2) ? num1 : num2;.
Run a loop from 1 to min, increment loop by 1 in each iteration. The loop structure should look like for(i=1; i<=min; i++).
Inside the loop check if i is a factor of two numbers i.e. if i exactly divides the given two numbers num1 and num2 then set i as HCF i.e. hcf = i.
please mark me as brainlst
Similar questions