ADVERTISEMENT
ADVERTISEMENT

VB.Net program to calculate the Highest Common Factor (HCF)

Here, we are going to learn how to calculate the Highest Common Factor in VB.Net?
Submitted by Nidhi, on November 26, 2020

Here, we will read two integer numbers from the user and calculate the Highest Common Factor, and print that on the console screen.

Program/Source Code:

The source code to calculate the Highest Common Factor is given below. The given program is compiled and executed successfully.

'VB.Net program to calculate the Highest Common Factor

Module Module1

    Sub Main()

        Dim num1 As Integer = 0
        Dim num2 As Integer = 0
        Dim temp As Integer = 0

        Console.Write("Enter number1: ")
        num1 = Integer.Parse(Console.ReadLine())

        Console.Write("Enter number2: ")
        num2 = Integer.Parse(Console.ReadLine())

        While Not (num2 = 0)
            temp = num1 Mod num2
            num1 = num2
            num2 = temp
        End While

        Console.WriteLine("Highest Common Factor is: {0}", num1)

    End Sub

End Module

Output:

Enter number1: 100
Enter number2: 40
Highest Common Factor is: 20
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains the Main() method. In the Main() method we created three local variables num1, num2, and temp that are initialized with 0. After that, we read the value of num1 and num2 from the user.

While Not (num2 = 0)
    temp = num1 Mod num2
    num1 = num2
    num2 = temp
End While

In the above code, we calculated the Highest Common Factor and print the result on the console screen.

VB.Net Basic Programs »



ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.