C program to find LCM of two numbers

LOGIC:

Find the largest number that is divided by both the numbers.

Program:


#include <stdio.h>
int main ()
{
  int n1, n2, max = 0;
  scanf ("%d %d", &n1, &n2);
  max = (n1 > n2) ? n1 : n2;
  while (1)
    {
      if (max % n1 == 0 && max % n2 == 0)
{
  printf ("%d", max);
  break;
}
      max++;
    }
  return 0;
}

Output:

6 7                                                                                                                                            
42                                                                                                                                             

6 3                                                                                                                                              
6       

Comments

Popular posts from this blog

C program to print the following Pattern

For any given matrix find the path from the start to the end which gives the maximum sum. Traverse only right or down. Example: starting index is 15 (left top) and ending index is 10 (bottom right) 15 25 30 45 25 60 70 75 10 O/P:15->45->70->75->10 sum is 215

c++ program to print string along the diagonals of the matrix.