SysYTestcases/function_2020/60_while_fibonacci.sy
ridethepig 13f3cb710a init
2023-05-16 00:56:56 +08:00

28 lines
272 B
Plaintext

int n;
int fib(int p){
int a;
int b;
int c;
a = 0;
b = 1;
if ( p == 0 ){
return 0;
}
if ( p == 1 ){
return 1;
}
while ( p > 1 ){
c = a + b;
a = b;
b = c;
p = p - 1;
}
return c;
}
int main(){
n = getint();
int res;
res = fib( n );
return res;
}