简体   繁体   中英

Why am i Getting this error? error: invalid operands of types 'int' and 'int(int, int)' to binary 'operator/'

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int n1, n2;
    cin >> n1 >> n2;
    int lcm =  n1 * n2; //Line 2
    int rem = lcm / gcd;
    cout << gcd(n1, n2) << endl;
    cout << rem << endl;

I am getting an Error at line 2 saying " error: invalid operands of types 'int' and 'int(int, int)' to binary 'operator/' ". I Use Sublime Text Editor to Compile.

You are getting the error because you cannot divide integers by functions.

Instead of

    int rem = lcm / gcd;

it seems you wanted to call the function gcd .

    int rem = lcm / gcd(n1, n2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM