Reputation: 151
I am trying to create a simple(supposedly) single line function named f2
that takes one int argument named x
, and returns a double value equal to 1.0/x
but doesn't print anything. I am getting error after error, and I am not sure what the protocols are for creating and separating different parts of a function on one line or if I can even do this. Here is what I have:
f2(int x) { scanf("%i", &x); int c = (1.0/x) return x}
I am trying to use ch to see if it runs and I am not sure if that could, possibly, also be the problem.
Upvotes: 1
Views: 62
Reputation: 1576
Your code doesn't do any part of what you specify...
There is no reason to use scanf. You also use an int to store a floating point value. You also don't return the calculated value.
Here is your function, expanded for clarity:
double f2(int x){
double val = 1.0 / x;
return val;
}
One line:
double f2(int x){ return 1.0 / x; }
Upvotes: 2