> n1 >> n."/> > n1 >> n."/> > n1 >> n"/>
خرید بک لینک

gameover.blog.ir


1. Source Code to Find LCM

#include <iostream>
using namespace std;

int main() {
    int n1, n2, max;
    cout << "Enter two numbers: ";
    cin >> n1 >> n2;
    
    max = (n1 > n2) ? n1 : n2; // maximum value between n1 and n2 is stored in max

    do {
        if (max%n1 == 0 && max%n2 == 0) {
            cout << "LCM = " << max;
            break;
        }
        else
            ++max;
    }
    while (true);
    
    retu 0;
}

Output

Enter two numbers: 12
18
LCM = 36



Source Code to find LCM using HCF

LCM = (n1*n2)/HCF

#include <iostream>
using namespace std;

int main() {
    int n1, n2, temp1, temp2, lcm;
    cout << "Enter two numbers: ";
    cin >> n1 >> n2;

    temp1 = n1;
    temp2 = n2;
    
    while(temp1 != temp2) {
        if(temp1 > temp2)
            temp1 -= temp2;
        else
            temp2 -= temp1;
    }

    lcm = (n1 * n2) / temp1;

    cout << "LCM = " << lcm;
    retu 0;
}



برچسب: نویسنده: ایلیا حیدری تاريخ: شنبه 17 مهر 1395 ساعت: 2:07

صفحه بندی