#include <stdio.h>
      int lcm() {
        int n1, n2, max;
        printf("Enter two positive integers: ");
        scanf("%d %d", &n1, &n2);
        // maximum number between n1 and n2 is stored in max
        max = (n1 > n2) ? n1 : n2;
        while (1) {
          if (max % n1 == 0 && max % n2 == 0) {
            printf("The LCM of %d and %d is %d.", n1, n2, max);
        return 0;
      C language logo

      Lowest common multiple

      Codiga's C Recipes

      Calculate the LCM (Lowest common multiple) of two numbers entered by the user.

      The LCM of two integers n1 and n2 is the smallest positive integer that is perfectly divisible by both n1 and n2 (without a remainder). For example, the LCM of 72 and 120 is 360.


        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.