[try Beta version]
Not logged in

 
I couldn't solve it in c++ can you help me

Nov 18, 2013 at 8:03am
Write a program that asks the user to prompt an Integer number and then test whether it is Palindrome Numbers or not.
The following are Palindrome numbers:
1. 22
2. 333
3. 67876
4. 44444
5. 123454321
Nov 18, 2013 at 8:09am
Hint: read it as a std::string and then keep comparing ith and (n-1-i)th characters.
Nov 18, 2013 at 8:17am
Hi abhishekm71 Thank you But I am new in the site I am a beginner I didn't understand what you said ?? can you help me more??
Nov 18, 2013 at 9:57am
I don't want to give you entire code.

The basic algorithm is as follows:

1. Read the number as a string.
1
2
3
std::string number;
std::cout << "Please enter a number" << std::endl;
std::cin >> number;


2. Using a 'for' loop, iterate over the string characters and keep comparing the ith characters with (length - 1 - ith) character.

3. If all comparisons give 'equal' result, then the number is a palindrome. Else not.
Nov 18, 2013 at 10:10am
You could edit your post to move it to the "Beginners" forum.

Courses usually provide info first and then give homework that depend on that info. The purpose of homework is to learn. You do learn best by doing.

Even though you may be a beginner, you must know something. Use that and do as much you can. Then show the result.
Nov 18, 2013 at 11:25am
abhishekm 71 I know I don't want to give it to me but the problem that I don't understand it clearly and especially Palindrome
and keskiverto thank you I know that's why I signed up here...
Nov 18, 2013 at 12:12pm
The loop looks two characters at a time, one from both ends of the word. If the are not the same, then the word is not a palindrome.

There is a way to hide the loop by using existing library code. First, make a copy of the word (std::string copy constructor). Then reverse that copy (std::reverse). Last, test the equality of the reversed copy and the original (std::string::operator==).


Start simple. Make a for-loop that prints out every character of the word, one at a time, and the index of that character.
Nov 18, 2013 at 1:34pm
bool F(int number) //2013 - 11 - 02
{
std::string y = std::to_string(number);
std::string x = std::to_string(number);

for (int b = 0; b < x.length() / 2; b++)
std::swap(x[b], x[x.length() - b - 1]);
if (y == x)
return 1;
return 0;
}

change int to unsigned long long,if you want to check the palindromation of huge number
Nov 18, 2013 at 2:11pm
I found it ... it as follows

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{


int x,y,sum=0,z;
cout <<"Enter a number:";
cin>>x;
z=x;

while(x!=0)
{
y=x%10;
x=x/10;
sum=sum*10+y;

}


if(z==sum)

cout<<"The number you entered is a Palindrome."<<endl;

else


cout<<"The number you entered is not a Palindrome."<<endl;
getch ();
return 0;
}


Thanks a lot
Topic archived. No new replies allowed.