C Program to Find HCF and LCM
Writing a program to find the HCF and LCM of two whole numbers is a popular tutorial/question in C programing language. It gives the idea of basic loop techniques, some mathematical operations along with the fundamental input output functions of C library.
1 |
#include <stdio.h>int main(){int m, n, a, b, t, hc, lc; // variable declarationprintf(" Enter two numbers: ");scanf("%d%d", &a, &b);m = a;n = b;while (n != 0){t = n;n = m % n;m = t;}hc = m; // hcflc = (a*b)/hc; // lcmprintf(" The highest Common Factor %d and %d = %d\n", a, b, hc);printf(" The Least Common Multiple of %d and %d = %d\n", a, b, lc);return 0;}</stdio.h> |