Program to find GCD/HCF of two numbers in Kotlinpackage com.includehelp.basic import java.util.* //Main Function entry Point of Program fun main(args: Array<String>) { //Input Stream val scanner = Scanner(System.`in`) //input First integer print("Enter First Number : ") val first: ...
// Java program to calculate the // HCF of two numbers import java.util.Scanner; public class Main { static int CalHcf(int num1, int num2) { int temp = 0; if (num1 == 0 || num2 == 0) return 0; while (num2 != 0) { temp = num1 % num2; num1 = num2; num2 = ...
After the final iteration of the loop, n1 = n2 = 4. This is the value of the GCD/HCF since this is the greatest number that can divide both 16 and 76.We can also find the GCD of two numbers using function recursion.Share on: Did you find this article helpful?
// JavaScript program to find the LCM of two integers var hcf; const num1 = prompt('Enter a first integer: '); const num2 = prompt('Enter a second integer: '); while(num1 != num2){ if(num1 > num2) num1 -= num2; else num2 -= num1; } hcf = num1; // find LCM let...
Example 1: Find HCF using for Loop // program to find the HCF or GCD of two integers let hcf; // take input const number1 = parseInt(prompt('Enter a first positive integer: ')); const number2 = parseInt(prompt('Enter a second positive integer: ')); // looping from 1 to number...
This user-defined function (longestPalindrome) contains the logic to find the longest palindromic element in the given array. index=longestPalindrome(a,n); In this function, we first store the array passed as parameter (p) into another array (a). We do so because, we need to preserve the...
C Program To Find Maximum Between Three Numbers | C Programs C Program To Find Reverse Of An Array – C Programs C Program To Check Character Is Uppercase or Lowercase | C Programs C Program To Check A Number Is Negative, Positive Or Zero | C Programs C Program To Calculate Profit or ...
Here we will learn how to write a C++ program inorder to check the given number is ARMSTRONG or not. C++ program to find Armstrong number C++ PROGRAM TO CHECK GIVEN NUMBER IS ARMSTRONG NUMBER OR NOT #include<iostream> #include<iomanip> int main(){ int num,r,sum,temp; for(num=1;num...
C program to find the remainder of two numbers without using modulus (%) operator/* * Program to get remainder without using % operator. */ #include <stdio.h> int main() { int a,b,rem; printf("Enter first number :"); scanf("%d",&a); printf("Enter second number :"); scanf("...
// program to find the LCM of two integers let hcf; // take input const number1 = prompt('Enter a first positive integer: '); const number2 = prompt('Enter a second positive integer: '); // looping from 1 to number1 and number2 to find HCF for (let i = 1; i <= number1 ...