Thursday, September 10, 2020

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

 

//JAVA Program to find HCF of two numbers

package Diploma;

import java.util.Scanner;

public class HCF1 

{

public static void main(String args[]){

      int a, b, i, hcf = 0;

      Scanner sc = new Scanner(System.in);

      System.out.println("Enter first number :: ");

      a = sc.nextInt();

      System.out.println("Enter second number :: ");

      b = sc.nextInt();


      for(i = 1; i <= a && i <= b; i++) 

      {

         if( a%i == 0 && b%i == 0 )

         hcf = i;

      }

      System.out.println("HCF of given two numbers = "+hcf);    

}

}

No comments:

Post a Comment

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 ...