usingMaths.com
From Theory to Practice - Math You Can Use.







<< PreviousNext >>

C# Program to Calculate HCF (GCD) with User Input - Kids Fun Project



Understanding the HCF Algorithm in C#

This C# program calculates the HCF (Highest Common Factor) using user input and the Fast HCF C# Code from the previous lesson.
Let's add some input mechanism so our user enters the set of numbers whose H.C.F. we are to find.


Combining the H.C.F. (G.C.D.) C# Code and Collecting User Input

All we need is a main C# code that asks the user for input.
For this purpose, we'll use the Console.ReadLine() library function.

How to use the HCF Code in C#

The user gets to enter his/her choice of numbers for the HCF C# algorithm.
After entering each number, the user presses <Enter>.
After the user has entered every of his/her numbers, the user enters the word done to see the result.


Note: You can comment out the C# code for the main class from the previous lesson if you have been following.



So! C# Fun Practice Exercise - Find HCF with User Input

As a fun practice exercise, feel free to try out your own numbers, and see how the C# code finds the HCF of your input numbers.









<< PreviousNext >>