c002: 10696 - f91

zerojudge https://zerojudge.tw/ShowProblem?problemid=c002

uva https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1637

• If N ≤ 100, then f91(N) = f91(f91(N + 11)); • If N ≥ 101, then f91(N) = N − 10.



#include <iostream>
using namespace std;
int f91(int);
int main(){
  int n;
  while (cin >> n && n!=0){
    cout << "f91(" << n << ") = " <<f91(n) <<endl;
  }
}
int f91(int num){
  if (num <=100) return f91(f91(num+11));//遞迴
  else return num-10;//終止條件
}

results matching ""

    No results matching ""