Question #5291

4. GCD * LCM = a*b

Where * is the multiplication symbol.

Suppose that the user only enters 3 out of 4 values and -1 for the 4th value. You have to print the 4th value on the basis of the entered values. For example if the user enters 3 and 6 for the values a and b and 3 and -1 for the gcd and lcm then the value of lcm would be 6.

Where * is the multiplication symbol.

Suppose that the user only enters 3 out of 4 values and -1 for the 4th value. You have to print the 4th value on the basis of the entered values. For example if the user enters 3 and 6 for the values a and b and 3 and -1 for the gcd and lcm then the value of lcm would be 6.

Expert's answer

// StudentName.cpp : Defines the entry point for the console

application.

//

#include "stdafx.h"

#include "conio.h"

#include

<iostream>

#include "string"

using namespace std;

int

_tmain(int argc, _TCHAR* argv[])

{

double

a,b,gcd,lcm;

cout<<"Enter number

a=";

cin>>a;

cout<<"Enter number

b=";

cin>>b;

cout<<"Enter number

gcd=";

cin>>gcd;

cout<<"Enter number lcm(enter

-1)=";

cin>>lcm;

if(lcm==-1){

lcm=a*b/gcd;

cout<<lcm;

}

getch();

return

0;

}

application.

//

#include "stdafx.h"

#include "conio.h"

#include

<iostream>

#include "string"

using namespace std;

int

_tmain(int argc, _TCHAR* argv[])

{

double

a,b,gcd,lcm;

cout<<"Enter number

a=";

cin>>a;

cout<<"Enter number

b=";

cin>>b;

cout<<"Enter number

gcd=";

cin>>gcd;

cout<<"Enter number lcm(enter

-1)=";

cin>>lcm;

if(lcm==-1){

lcm=a*b/gcd;

cout<<lcm;

}

getch();

return

0;

}

## Comments

## Leave a comment