C++ Program to Find LCM and HCF of Two Numbers on Command Line

You are currently viewing C++ Program to Find LCM and HCF of Two Numbers on Command Line

Using this tutorial, We are going to discuss the topic about “C++ Program to Find LCM and HCF of Two Numbers on Command Line“. Can I start the tutorial to teach the concept to you below? Come on! Let’s go.

C++ Program to Find LCM and HCF of Two Numbers on Command Line

Program Code

/* To find the LCM and HCF of 2 given numbers*/

#include<stdio.h>
#include<conio.h>

void main(){
	int m, n, a, b, temp;

	START:
	printf("nEnter the numbers m and n :");
	scanf("%d%d",&m,&n);
	a = n; b = m;
	if (m*n == 0)
		printf("HCF and LCM cannot be enumerated for 0");
	else{
		while (n>0){
			temp = n;
			n = m % n;
			m = temp;
		}
		printf("HCF = %dt LCM = %dn",m,a*b/m);

		goto START; 
	}
	_getch();


}

Final Thoughts

That’s it developers. This article about “C++ Program to Find LCM and HCF of Two Numbers on Command Line” will be very helpful to you. If you face any problems during the program execution then don’t worry. Please contact us via the comment section. We are always ready to help you. Share this article with others.

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply