Pseudocode Examples

Pseudocode to Find LCM of Two Numbers1 min read

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)

This code calculates the least common multiple (LCM) of two integers. The LCM is the smallest positive integer that is a multiple of both integers. Here is a brief explanation of how it works:




You may also like: Pseudocode Examples

  1. The program declares three variables: n1, n2, and lcm.
  2. The program prompts the user to enter two integers and stores them in n1 and n2.
  3. The program initializes the lcm variable to the larger of the two integers (n1 and n2).
  4. The program enters an infinite loop.
  5. Inside the loop, the program checks whether lcm is a multiple of both n1 and n2. If it is, the program prints out the LCM and breaks out of the loop. If it is not, the program increments lcm by 1 and continues the loop.
  6. The program ends.

Flowchart

Leave a Comment