Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1)
- #include <iostream>
- using namespace std;
- int rev(int, int);
- int main()
- {
- int n, a;
- cin >> n;
- cout << rev(a=0, n) <<endl;
- return 0;
- }
- int rev(int a, int n)
- {
- if (n==0)
- return a;
- else
- {
- return rev(a*10 +n%10, n/10);
- }
- }
- 2)
- #include <iostream>
- using namespace std;
- int soma(int);
- int main()
- {
- int n;
- cin >> n;
- cout << soma(n) << endl;
- return 0;
- }
- int soma(int n)
- {
- if (n == 1)
- return 1;
- if (n > 1)
- {
- return n + soma(n-1);
- }
- }
- 3)
- #include <iostream>
- using namespace std;
- int pot(int, int);
- int main()
- {
- int k, n;
- cin >> k >> n;
- cout << pot(k,n) << endl;
- return 0;
- }
- int pot(int x, int y)
- {
- if (y==0)
- return 1;
- if (y==1)
- return x;
- if (y>1)
- return x * pot(x, y-1);
- }
- 4)
- #include <iostream>
- using namespace std;
- int mdc(int, int);
- int main()
- {
- int a, b;
- cin >> a >> b;
- cout << mdc(a,b) << endl;
- return 0;
- }
- int mdc(int x, int y)
- {
- if (y==0)
- return x;
- else
- return mdc(y, x%y);
- }
- //pra calcluar mmc é (a*b)/mdc; mas n sei como faz a função pra isso;
- 5)
- #include <iostream>
- using namespace std;
- int verif(int, int, int);
- int main()
- {
- int n, j, x;
- cin >> n >> j;
- cout << verif(n, j, x=0) <<endl;
- return 0;
- }
- int verif(int n, int j, int x)
- {
- if (n==0)
- return x;
- if (n >= 1)
- {
- if(n%10 == j)
- ++x;
- verif(n/10, j, x);
- }
- }
- 6)
- #include <iostream>
- using namespace std;
- int multip_rec(int, int);
- int main()
- {
- int x, y;
- cin >> x >> y;
- cout << multip_rec(x,y) << endl;
- return 0;
- }
- int multip_rec(int n1, int n2)
- {
- if (n2 == 0)
- return 0;
- if (n2 == 1)
- return n1;
- if (n2>1)
- return n1 + multip_rec(n1, n2-1);
- }
- 7)
- #include <iostream>
- using namespace std;
- void cres(int, int);
- int main()
- {
- int x, y;
- cin >> x;
- cres(x,y=0);
- return 0;
- }
- void cres(int n, int h)
- {
- if (n==0)
- cout << 0 <<endl;
- if (h <= n and n != 0)
- {
- cout << h <<endl;
- cres(n, h+1);
- }
- }
- 7.1)
- #include <iostream>
- using namespace std;
- void cres(int);
- int main()
- {
- int x;
- cin >> x;
- cres(x);
- return 0;
- }
- void cres(int n)
- {
- static int k = -1;
- if (n==0)
- {
- cout << ++k <<endl;
- }
- else
- {
- cout << ++k <<endl;
- cres(n-1);
- }
- }
- 8)
- #include <iostream>
- using namespace std;
- void cres(int, int);
- int main()
- {
- int _aux;
- cin >> _aux;
- cres(_aux,0);
- return 0;
- }
- void cres(int n, int _aux =0)
- {
- if (n==0)
- cout << n <<endl;
- if (_aux <= n and n != 0)
- {
- if (_aux%2==0)
- cout << _aux <<endl;
- cres(n, _aux +1);
- }
- }
- 9)
- #include <iostream>
- using namespace std;
- void cres(int);
- int main()
- {
- int x;
- cin >> x;
- cres(x);
- return 0;
- }
- void cres(int n)
- {
- if (n==0)
- cout << n <<endl;
- if (n>=1)
- {
- if (n%2==0)
- cout << n <<endl;
- cres(n-1);
- }
- }
- 12)
- #include <iostream>
- #include <cmath>
- using namespace std;
- int fatex(int);
- int main()
- {
- int n;
- cin >> n;
- cout << fatex(n) << endl;
- return 0;
- }
- int fatex(int n)
- {
- if (n >= 0)
- return pow(n, fatex(n-1));
- else
- return n;
- }
- 13)
- #include <iostream>
- using namespace std;
- int trib(int);
- int main()
- {
- int n;
- cin>> n;
- cout << trib(n) << endl;
- return 0;
- }
- int trib(int n)
- {
- if (n<=2)
- {
- if (n<=1)
- return 0;
- else
- return 1;
- }
- else
- return trib(n-1) + trib(n-2) + trib(n-3);
- }
- 14)
- #include <iostream>
- using namespace std;
- int bin(int);
- int main()
- {
- int ndec;
- cin >> ndec;
- cout << bin(ndec) << endl;
- return 0;
- }
- int bin(int nbin)
- {
- if ( nbin < 2 )
- return nbin;
- else
- return ( 10 * bin( nbin / 2 ) ) + nbin % 2;
- }
- 15)
- #include <iostream>
- using namespace std;
- int h(int,int);
- int main()
- {
- int a, b;
- cin >> a >> b;
- cout << h(a,b) << endl;
- return 0;
- }
- int h(int m,int n)
- {
- if (n==1 or m==1)
- {
- if (n==1)
- return m+1;
- if (m==1)
- return n+1;
- }
- else
- return h(m,n-1) + h(m-1,n);
- }
- 16)
- #include <iostream>
- using namespace std;
- int somaSerie(int,int,int);
- int main()
- {
- int a, b, c;
- cin>> a >> b >> c;
- cout << somaSerie(a, b, c) << endl;
- return 0;
- }
- int somaSerie(int i,int j,int k)
- {
- if (i+k <= j)
- return i + somaSerie(i+k, j, k);
- else
- return i;
- }
- 17)
- #include <iostream>
- using namespace std;
- int somDig(int, int);
- int main()
- {
- int a, n;
- cin >> n;
- cout << somDig(a=0, n) << endl;
- return 0;
- }
- int somDig(int a, int n)
- {
- if (n==0)
- return a;
- else
- return somDig(a + n%10,n/10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement