Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Linux Foundation Training and Certification

Teach Your Child To Read

Disclosure: My content contains affiliate links.

32,310 questions

42,485 answers

573 users

How to calculate the HCF (Highest Common Factor) of two integers in Dart

1 Answer

0 votes
// Highest common factor (HCF) = the largest integer that two or more numbers can be divided by
 
class MyClass
{
    static int HFC(int divided, int divisor) {
        int? remainder;
        var hcf = 0;
        do {
            remainder = divided % divisor;
            if (remainder == 0) {
                hcf = divisor;
            }
            else {
                divided = divisor;
                divisor = remainder;
            }
        } while (remainder != 0);
         
        return hcf;
    }
     
    static void main()
    {
        var divided = 18;
        var divisor = 27;
         
        print("HCF = " + (MyClass.HFC(divided, divisor)).toString());
    }
}
 
void main() {
    MyClass.main();
}
 
 
 
 
/*
run:
 
HCF = 9
 
*/

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Apr 27, 2023 by avibootz
edited Jan 9 by avibootz
...