Thursday, September 10, 2020

JAVA Program | HCF & LCM of two Numbers | Diploma Computer Engineering |

 

//JAVA Program to find HCF & LCM of two numbers

package Diploma;

import java.util.Scanner;

public class HCFLCM 

{

   public static void main(String args[]){

      int temp1, temp2, num1, num2, temp, hcf, lcm;

      Scanner scanner = new Scanner(System.in);


      System.out.print("Enter First Number: ");

      num1 = scanner.nextInt();

      System.out.print("Enter Second Number: ");

      num2 = scanner.nextInt();

      scanner.close();


      temp1 = num1;

      temp2 = num2;


      while(temp2 != 0)

      {

         temp = temp2;

         temp2 = temp1%temp2;

         temp1 = temp;

        }

      hcf = temp1;

      lcm = (num1*num2)/hcf;

      System.out.println("HCF = "+hcf);

      System.out.println("LCM = "+lcm);

   }

}    


1 comment:

  1. Affordable Samsung 19"" Flat in UAE, 1366x768 LED Monitor in UAE
    https://gccgamers.com/gaming-vr.html/samsung-19-flat-1366x768-monitor-ls19a330nhmxue.html

    ReplyDelete

CMS - 2024 || JAC INTERMEDIATE EXAMINATION - 2024 || 12th COMPUTER SCIENCE!

  Part-A Multiple Choice Questions 1) Who is the developer C++? a) Von Neumann b) Dennis M. Ritchie c) Charles Babbage d) Bjarne Stroustrup ...