You are on page 1of 2

Task 2

#include<iostream>
using namespace std;
int gcd(int a, int b) {
if (a == 0 || b == 0)
return 0;
else if (a == b)
return a;
else if (a > b)
return gcd(a - b, b);
else return gcd(a, b - a);
}
int main() {
int a = 64, b = 72;
cout << "GCD of " << a << " and " << b << " is " << gcd(a, b);
system("pause");
}

Task 3
#include <iostream>
using namespace std;

// recursive function that returns the reverse of digits


int rev(int n, int temp)
{

if (n == 0)
return temp;

// stores the reverse of a number


temp = (temp * 10) + (n % 10);

return rev(n / 10, temp);


}

int main()
{

int n;
cout << "enter number: " << endl;
cin >> n;

int temp = rev(n, 0);


if (temp == n)
cout << "yes" << endl;
else
cout << "no" << endl;
system("pause");
}

You might also like