Site icon T4Tutorials.com

Program of LCM of a number in C Plus Plus (C++) and C with flowchart

Program of LCM of a number in C Plus Plus (C++) and C with flowchart

In this tutorial, we will learn about the followings;

  1. Flowchart of a program of LCM of a number
  2. Program of LCM of a number in C Plus Plus (C++)
  3. 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++ and C with flowchart
Figure: Program of LCM of a number in C Plus Plus C++ and C with the flowchart.

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 Plus Plus and C with flowchart and example
Figure: Program of LCM of a number in C Plus Plus and C with the flowchart.

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

Program of LCM of a number in C Plus Plus and C with flowchart and example
Figure: Program of LCM of a number in C Plus Plus and C with the flowchart.
Exit mobile version