猿问
有函数f(x),当x=0,f(x)=0;当x为奇数时,f(x)=f(x-1)+3;
当x为偶数时,f(x)=f(x-1)+5;
慕桂英8003428
浏览 1167
回答 1
1回答
皓韵儿
#include <stdio.h> int f(int x){ if(x == 0) return 0; else if(x % 2 == 0){ return f(x - 1) + 5; } else { return f(x - 1) + 3; } } int main(){ int x; scanf("%d", &x); int t = f(x); printf("%d\n", t); return 0; }有什么不明白的可以再问我。
3
0
0
随时随地看视频
慕课网APP
相关分类
C++
typedef入门问题
1 回答
我要回答