0
Why this code return "0" as result?
#include <stdio.h> #include <float.h> int a(int b){ int c; while (b > 0){ return b + a(b - 1); } } int main() { printf("%i",a(10)); return 0; }
3 Answers
+ 2
It returns 0 as an exit status meaning no errors have occured. (plus its "int main" you need to return an integer)
If there is a problem, it will exit with anything but 0, usually 1.
0
I write a recursive function with while statement instead of if ...else statement.But the result is not I expect.Why is this?
0
The result of the code is 55 which is summation of values 10+9+8+...+1.