Make Your Search Easy ! :) Use me

Monday, October 16, 2017

Common Multiple

C++ program to find the nth common multiple of two given numbers.


#include <iostream>
#include <conio.h>
using namespace std;

int main()
  {
    int a,b,n=0,num;
    std::cout << "Enter two numbers to find common multiple : "<< "\n";
    std::cin>>a>>b;
    std::cout<<"Enter the the common multiple required : ";
    std::cin>>num;
    for (size_t i = 4; ; i++)
    {
      if(i%a==0 && i%b==0)
          n++;
      if (n==num) {
        std::cout<<i;
        break;
      }
    }
    getch();
    return 0;
  }

No comments:

Post a Comment