int fun(int x){return (x==1)?1:(x+fun(x-1))}; fun(2);
时间: 2023-11-22 20:05:45 浏览: 80
The code you provided defines a recursive function named "fun" that takes an integer argument "x" and returns the sum of all integers from 1 to x, inclusive. The function is implemented using recursion, and the function definition is correctly terminated with a semicolon.
The second part of the code `fun(2);` calls the "fun" function with an argument of 2, and expects to receive the result of the function call.
When the "fun" function is called with an argument of 2, the function recursively calls itself with an argument of 1, and then adds 2 to the result of the recursive call. The recursive call returns 1, because 1 is equal to 1. Therefore, the total sum returned by the function is 2 + 1 = 3.
So, the result of the function call `fun(2)` is 3.
阅读全文