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
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);
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.
@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?
@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.
@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.
#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:
Don't just add to a totally unrelated article, even if it's your own.
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:
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]
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.