Function

What is the correct answer and How is it calculated?.

#include <iostream>
using namespace std;

int fun(float a, float b) {
return a / b;
}

int main() {
cout << fun(fun(1.0,2.0),fun(2.0,1.0));
return 0;
}.
[/code]
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12

#include <iostream>
using namespace std;

int fun(float a, float b) {
return a / b;
}

int main() {
cout << fun(fun(1.0,2.0),fun(2.0,1.0));
return 0;
}


correct answer is 0

But if you change the return value of fun() to float then you get 0.25

Depends on which type of numerical answer you want.

PS use [code] at the top. And remove full stop at the end of main()
Last edited on
Thanks
Topic archived. No new replies allowed.