A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C++ Program To Find The GCD And LCM Of Two Numbers
Q:

C++ Program To Find The GCD And LCM Of Two Numbers

0

Write A C++ Program To Find The GCD And LCM Of Two Numbers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream.h>

int main() {
  int a, b, x, y, t, gcd, lcm;

  cout<<"Enter two integers\n";
  cin>>x>>y;

  a = x;
  b = y;

  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }

  gcd = a;
  lcm = (x*y)/gcd;

  cout<<"Greatest common divisor of "<<x<<" and "<<y<<"="<<gcd;
  cout<<"Least common multiple of "<<x<<" and "<<y<<"="<<lcm;

  return 0;
}

 

Output:

Enter two integers

15

33

Greatest common divisor of 15 and 33  =3

Least common multiple of 15 and 33 =165

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now