answersLogoWhite

0

Problem Statement for LCM:

Enter Two digits by a user and get its LCM

Answer:

#include

#include

void main()

{

int x,y,i,j;

clrscr();

printf("Enter Two Digits");

scanf("d",&x,&y);

for(i=1;i<=x;i++)

{

for(j=1;j<=y;j++)

{

if(y*i==x*j)

{

printf("LCM is %d\n",y*i);

i=i+x;

}

}

}

getch();

}

OR

there will be another easy way to solve it...

Answer:

#include

#include

void main()

{

int x,y,i,;

clrscr();

printf("Enter Two Digits = ");

scanf("d",&x,&y);

for(i=1;i<=x*y;i++) {

if(i%x==0&&i%y==0)

{

printf(LCM is %d",i);

break;

}

}

getch();

}

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
More answers

Hey Friends here is the program of HCF and LCM with output:

Statement of C Program: Find The LCM and HCF of Two Numbers :

#include #include

void main()

{

int num1 , num2 , lcm , gcd , remainder , numerator , denominator ;

clrscr();

printf( "Enter two numbers\n");

scanf(" %d%d " , &num1 , &num2 );

if (num1 > num2)

{

numerator=num1;

denominator=num2;

}

else

{

numerator = num2 ;

denominator = num1 ;

}

remainder = num1 % num2;

while ( remainder != 0)

{

numerator = denominator;

denominator = remainder;

remainder = numerator % denominator;

}

gcd = denominator;

lcm = (num1 * num2 ) / gcd;

printf("GCD of %d and %d =%d\n" , num1, num2, gcd);

printf(" LCM of %d and %d= %d\n" , num1, num2, lcm);

getch();

}

Output:

Enter two numbers

5

15

GCD of 5 and 15 = 5

LCM of 5 and 15 = 15

User Avatar

Wiki User

12y ago
User Avatar

01#include <iostream>

02using namespace std;

03

04

05int gcf(int a, int b ) {

06 int rem = a % b;

07 while (rem != 0){

08 rem = b % rem;

09 rem--;

10 return b;

11 }

12

13}

14

15

16int main () {

17

18 int x, y;

19 cout << "Enter two integers: ";

20 cin >> x >> y;

21

22 cout << "The greatest common factor of " << x << " and " << y

23 << " is " << gcf(x, y) << endl;

24

25 return 0;

26}

User Avatar

Wiki User

12y ago
User Avatar

int gcd (int x, int y)

{

. if (x<0) x= -x;

. if (y<0) y= -y;

. if (x<y) { int tmp= x; x= y; y= tmp;}

. if (y==0) return x;

. else return gcd (y, x%y);

}

int LCM (int x, int y)

{

. int d;

. if (x<0) x= -x;

. if (y<0) y= -y;

. d= gcd (x, y);

. if (d==0) return d;

. else return x/d*y;

}

User Avatar

Wiki User

13y ago
User Avatar

Is this a question? If it is, the answer is: 'yes, do write'.

User Avatar

Wiki User

12y ago
User Avatar

void lcm(int m,int n)

{

int i;

for(i=1;i++)

{

if(i%m==0&&i%n==0)

return i;

}

User Avatar

Wiki User

13y ago
User Avatar

how to find the lcm using while loop

User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: How a C program to find LCM using while loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp