Skip to content

Instantly share code, notes, and snippets.

@modos
Created April 26, 2023 05:51
Show Gist options
  • Save modos/022009f31b0d1c3fbc0484097490150f to your computer and use it in GitHub Desktop.
Save modos/022009f31b0d1c3fbc0484097490150f to your computer and use it in GitHub Desktop.
دنباله بازگشتی
#include<bits/stdc++.h>
using namespace std;
int f(int x)
{
if(x == 0) return 5;
int tmp = f(x-1); // calculating f_{x-1}
if(x % 2 == 0) return tmp - 21;
else return tmp * tmp;
}
int main(){
int n;
cin >> n; // input
cout << f(n) << endl; // calling f to calculate f_n
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment