Program of LCM of a number in C Plus Plus (C++) and C with flowchart
In this tutorial, we will learn about the followings;
- Flowchart of a program of LCM of a number
- Program of LCM of a number in C Plus Plus (C++)
- Program of LCM of a number in C
Flowchart of a program of LCM of a number

Program of LCM of a number in C Plus Plus (C++)
#include<iostream>
#include<conio.h>
using namespace std;
void lcm(int,int);
int main()
{
int p,q;
cout<<"Enter two numbers: ";
cin>>p;
cin>>q;
lcm(p,q);
getch();
}
void lcm(int p,int q)
{
int i,j;
i=p;
j=q;
while(i!=j)
{
if(i < j)
{
i=i+p;
}
else
{
j=j+q;
}
}
cout<<"\nL.C.M of two number p="<<p<<" and q="<<q<<" is "<<i;
}
Output

Program of LCM of a number in C
#include<stdio.h>
#include<conio.h>
void lcm(int,int);
int main()
{
int p,q;
printf("Enter two numbers: ");
scanf("%d %d",&p,&q);
lcm(p,q);
getch();
}
void lcm(int p,int q)
{
int i,j;
i=p;
j=q;
while(i!=j)
{
if(i < j)
{
i=i+p;
}
else
{
j=j+q;
}
}
printf("\nL.C.M of p= %d and q= %d is: %d",p,q,i);
}
Output
