I am new to C++ and I am not sure how to use some of the cmath functions like div.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
if (n < 10) {
cout << div(n , 2);
}
return 0;
}
I am new to C++ and I am not sure how to use some of the cmath functions like div.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
if (n < 10) {
cout << div(n , 2);
}
return 0;
}
Copyright © 2021 Jogjafile Inc.
The reason
cout << div(n , 2)doesn't work is becausedivdoesn't return a number, insteaddivreturns a struct with 2 values in there,quotandrem.So when you use
div(10, 3), it will returns a object with.quot == 3and.rem == 1.To print the result of
div, you would need to first store the result, then print each members separately: