0
Dudes, I'm feeling issue in project 3 of c++ in sololearn. plz help in code.
case 1 and 3 are correct but 2,4 and 5 is not.
2 odpowiedzi
0
First you didn't assign any value to 'num'. Assign the value of x to num
num=x;
Then assign n=num before the while loop.
Finally return true or false by checking n==rev
0
here is my written code
#include <iostream>
using namespace std;
bool isPalindrome(int x) {
//complete the function
int digit,num, n,rev=0;
while (num!=0){
digit=num%10;
rev=(10*rev)+digit;
n=num;
num=num/10;
}
}
int main() {
int n;
cin >>n;
if(isPalindrome(n)) {
cout <<n<<" is a palindrome";
}
else {
cout << n<<" is NOT a palindrome";
}
return 0;
}