So I'm beginner starting software enginering studies

here condition:

Given number n ( n<=9999)

need to identify if this n is palindrom(ex. 7777,8228,0220...). Need to write in c++ language.thanks

Hi,

Firstly, convert your number into a string. Then check if it is a palindrome.
Also, paste code that you have already tried.

You can extract the digits and create he reverse number.

If you are given 564
Then 564 % 10 = 4
4 x 100 = 400
Then
564 / 10 = 56 Happens if you take the integer part after division
56 % 10 = 6
400 + 6 x 10 = 460 like this.

Else use string library functions, strrev() for reversing and strcmp() for comparison.

can anyone make an ex.i'll be thankfull

can anyone make an ex.i'll be thankfull

The point of the above two posts was to let you try. We can help you help yourself, not do your homework. Try whatever you can. If you face any problem, we can try to help.

what mean ,,char strn[9999];number .as i see i can write any number it works nothing changes?

what mean ,,char strn[9999];number .as i see i can write any number it works nothing changes?

I'm not sure i follow you. Can you paste the code here?

char strn[9999];
cout<<"Enter the string: ";
cin.getline(strn,9999);
int len=strlen(strn);
Member Avatar for SoreComet

As stated by NP Complete, the algorithm for the palindrome program is given as

int n,r,sum,temp;
cin>>n;

temp=num;
sum=0;

while(num!=0)   //Loop to reverse the number.
{
    r=n%10;
    n=n/10;
    sum=sum*10+r;
}

if(temp==sum)
    cout << "PALINDROME";
else
    cout << "NOT PALINDROME";

I find this snippet easy to understand.....yet the Palindrome program written using String functions is easy.

commented: Don't do HW for others +0
commented: I hope you got a good grade for doing his homework for him -3
commented: Appreciate your intent to help someone +13

@Ladis: Please do NOT give entire code. You will not help the OP in any way by doing this!

#include<iostream>
#include<string>
using namespace std; // the namespace for cout<< & such functions
int main()
{
char strn[5];
cout<<"Enter the string: ";
cin.getline(strn,5);
int len=strlen(strn);

bool plnd=true; // create a Boolean value, "plnd" to be used in our loop

for(int n=0;n!=len/2;n++) // do a loop from 0 to half the length of the string
{
if(plnd) // if it is a palindrome so far
{
if(strn[n]!=strn[len-n-1]) // check the characters match
{
plnd=false; // if they don't set the indicator to false
}

}

}

// if plnd is true cout "Palindrome" otherwise output "Not Palindrome"

if(plnd)
{
cout<<"Palindrome";
}
else
{
cout<<"Not Palindrome";
}

cin.get();

}

how to make what this code continue after typing second number?

maybe instead boolan I had to use other attribute?

If you want it to keep going then you would need to put lines 7 through 35 inside a loop.

for(int n=7;n!=len+35;n++)

like this ,if yes it counts what polindrome is not polindrome

@ marius2010

Please use proper formatting. See this.

Also, what is the use of line 15 ? You can always do this.

int flag = 1;

while( flag == 1)
{

    if(strn[n]!=strn[len-n-1])
    {
         flag = 0;

    }

}

if( flag == 0)

// Not palindrome

else 

// palindrome

just in case is there are posibility to make more than 1 typing in my code with boolan?

In your original description you said

Given number n ( n<=9999)

Inputting a string is not a number. You need to rethink your program and reconsider this suggestion.

Member Avatar for SoreComet

@anyone who flagged my post as bad

Dudes I am newbie to C++ and forums. I thought i was helping that dude.

@myk45 Sure man, I shall not post anymore snippets here

Hi Ladis,

@myk45 Sure man, I shall not post anymore snippets here

You still can submit code snippets, if you're interested. Check this out.

We just meant to say giving away entire code wouldn't help the OP. Insted, you can suggest ways of solving, or maybe give a brief pseudocode too.

Member Avatar for SoreComet

@myk45 sure man. Thanks for the advice

Dudes I am newbie to C++ and forums. I thought i was helping that dude.

Fair enough. Perhaps you should have waited till marius2010 demostrated that a genuine attempt to solve the problem was made.

Code snippets are a genuine aid in learning programming - one good snippet is worth a thousand words. There is no reason why you should completely refrain from posting them.

This has always been a forum where the oldies have grown senile and forgotten that they too were once newbies. At least as far as I am concerned, you just tried to help some one, and I for one appreciate that you tried to help.

commented: helping and doing their homework are two different things. You can help without writing *the* answer. -3
commented: Wise words! +0
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b=0,c,i;
for(i=11,i<=8999,i++)
{c=i;
while(i!=0)
{
a=i%10;
b=b*10+a;
i=i/10;
}
if(b==c)
cout<<"number"<<b<<"is palindrome";
i=c;
}
getch();
}

I think it will worku can change 8999 to 9999

@ rajat.sethi93 Void main is not standard. Please indent your code. You might want to get a compiler from this decade or at least something that is c++98 standard compliant. There are a number of free compilers/IDE's available. MSVC 2010 express and Code::blocks are a couple to check out.

IS any1 know really good book c++ for beginner?

need to find the smallest number from 6 numbers.first need to find the smallest from 2 numbers... then the smallest from the leftovers.simple-using if-else,but its consuming and time and space, second part needed

If you want to ask a new question, there are two things you need to understand:

1: Make a new article

Don't just add to a totally unrelated article, even if it's your own.

2: Study this:

You obviously didn't understand the first time, so here it is spelled out in detail (#9 is especially pertinant in your case):

[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    -Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not a coding service. We will help you fix your code.
    -If anyone posts working code for you, they are a cheater.
    -If you use that code you are a cheater.
  7. Do not bore us with how new you are. We can tell by your code.
    -Do not apologize. We were all new, and unless you are completely brain dead you will get better.
    -Do not ask us to "take it easy on you."
    -Do not say "I don't know what's going on." That's obvious since you posted for help. Use that time wisely by explaining as best you can so we can help.
  8. Do not apologize for posting 'late'. We don't have any expectations on when you should be posting - 10 minutes or 10 days. We aren't timing your responses.
  9. Do not post your requirements and nothing else. We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we will be hard on you.
  10. Do not attach files except when absolutely necessary. Most of us are not going to download files. Add the information to your post.
  11. Do not tell us how urgent it is. Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
  12. Create a good title for your post. The title C++ in the C++ forum is bloody redundant and worthless! What's wrong? equally so. Specifically what are you having trouble with? There is your title. (note: my program is not the answer.)

Think more about your next post so we don't have to play 20 questions to get the info we need to help you.
[/boilerplate_help_info]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.