InterviewSolution
| 1. |
The greatest common divisor (gcd) of two integers is calculated by the continued division method. Divide the larger number by the smaller the remainder reaches to zero. The last divisor results is gcd. Please guys i will mark as brainlist answer |
|
Answer» d ANSWER:-Question:WAP to calculate hcf of two numbers.Solution:1. In Java. import java.util.*;public class HCF { public static VOID main(String[] args) { int a, b, r; Scanner sc=new Scanner(System.in); System.out.print("Enter first NUMBER: "); a=sc.nextInt(); System.out.print("Enter second number: "); b=sc.nextInt(); while (a%b!=0) { r=a%b; a=b; b=r; } System.out.println("HCF: "+b); sc.close(); }}2. In Python. a=int(input("Enter first number: "))b=int(input("Enter second number: "))while not a%b==0: r=a%b a=b b=rprint("HCF: ",b)3. In C#include |
|