please code this for me in c++ using void, functions, loops, (basic c++ not complicated or highlevel please). I tried to code it myself but there are many mistakes I dont know how to fix so please write a similar one for me but it works.
The question is only 1 but it has 2 parts (2 different functions that should be in one code)
MY CODE:
#include using namespace std;int IsPalindrome(int p);void GCD();int main (){ int choice; cout < "please="" enter="" a="" choice:=""><> cout < "enter="" one="" for="" ispalindrome=""><> cout < "enter="" 2="" for="" gcd=""><> cout < "enter="" 3="" to="" exit="" the="" program=""><> cout < "choice:=""><> cin >> choice; if (choice == 1) { int p; cout < "please="" enter="" a="" 3="" digit="" number:=""><> cin >> p;if(p%10==p/100) { cout else { cout<> } else if (choice == 2) GCD(); else if (choice == 3) exit (0); return 0;}void GCD(){ int GCD(int n, int d){ if (n == 0) return d; if (d == 0) return n; if (n == d) return n; if (n > d) return GCD(n-d, d); return GCD(n, d-n);}int n,d;cout<"enter the="" value="" of="" n="<cin>>n;cout<<" enter="" the="" value="" of="" d="<cin>>d;cout<<" gcd="" of="">"enter><><" and="">"><><" is="">">}return 0;}Extracted text: a. Write a function called IsPalindrome that receives a 3-digit number and returns whether it is palindrome or not. b. Write a function, called GCD that receives two parameters n, d, and prints their greatest common divisor a. Now after you created the two functions, you have to write a main function that can call the above functions according to user choice. Write a menu that allows the user to select from the following options 1. To use the IsPalindrome function you have to enter 1. 2. To use the GCD function you have to enter 2. 3. To Exit the program you have to enter 3. [use exit(0)] Once the user select one of the above choices you have to read the value entered by the user and then to call the respective function.
int IsPalindrome(int p);void GCD();
int main (){ int choice; cout < "please="" enter="" a="" choice:=""><> cout < "enter="" one="" for="" ispalindrome=""><> cout < "enter="" 2="" for="" gcd=""><> cout < "enter="" 3="" to="" exit="" the="" program=""><> cout < "choice:=""><> cin >> choice; if (choice == 1) { int p; cout < "please="" enter="" a="" 3="" digit="" number:=""><> cin >> p;
if(p%10==p/100) { cout
else { cout<>
} else if (choice == 2) GCD(); else if (choice == 3) exit (0); return 0;}
void GCD(){ int GCD(int n, int d){ if (n == 0) return d; if (d == 0) return n; if (n == d) return n; if (n > d) return GCD(n-d, d); return GCD(n, d-n);}
int n,d;cout<"enter the="" value="" of="" n="<cin>>n;cout<<" enter="" the="" value="" of="" d="<cin>>d;cout<<" gcd="" of="">"enter><><" and="">"><><" is="">">
}
return 0;}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here