You are on page 1of 2

#include <iostream>

using namespace std;

//Friendly numbers
int sumDivisors(int n, int div){
if (div == 1){
return 1;
}
if (n % div == 0){
return div + sumDivisors(n, div - 1);
}
return sumDivisors(n, div - 1);
}

bool friends(int n, int m){


if (m == sumDivisors(n, n - 1) && n == sumDivisors(m, m - 1)){
return true;
}
return false;
}

//Write vertically
void printVertically(int n){
if (n < 10) {
cout << n << endl;
}
else{
printVertically(n / 10);
cout << n % 10 << endl;
}
}

int fact(int n){


if (n == 1 || n == 0){
return 1;
}
return n * fact(n - 1);
}

//Choice
int choice(int n, int m){
if (m == 0 || m == n){
return 1;
}
return fact(n) / (fact(m) * fact(n - m));
}

int main() {
int option, n, m;

while(option != -1){
cout << "\nChoose an option" << endl;
cout << "\nOption 1: friends numbers" << endl;
cout << "Option 2: write vertically" << endl;
cout << "Option 3: choice" << endl;
cout << "\nInsert -1 if you want to exit the code" << endl;
cout << "\nOption: ";
cin >> option;

switch(option){

case 1:
cout << "\nEnter the first number: ";
cin >> n;
cout << "Enter the second number: ";
cin >> m;
cout << endl;

if (friends(n, m)){
cout << n << " and " << m << " are friends" << endl;
}
else{
cout << n << " and " << m << " aren't friends" << endl;
}
break;

case 2:
cout << "\nEnter a number: ";
cin >> n;
cout << "\n";

printVertically(n);
break;

case 3:
cout << "\nThe first number must be higher than second number" <<
endl;
cout << "\nEnter the first number: ";
cin >> n;
cout << "Enter the second number: ";
cin >> m;
cout << endl;

if (n > m){
cout << "C(" << n << ", " << m << ") = " << choice(n, m) <<
endl;
}
else{
cout << "Doesn't meet the main condition" << endl;
}
break;
}
}
}

You might also like