Here you will get C++ program to check string is palindrome or not.
A string is called palindrome if it is equal to its reverse. For example bob is string palindrome.
#include<iostream> using namespace std; int main() { int i,j,len,flag=1; char a[20]; cout<<"Enter a string:"; cin>>a; for(len=0;a[len]!='\0';++len); for(i=0,j=len-1;i<len/2;++i,--j) { if(a[j]!=a[i]) flag=0; } if(flag==1) cout<<"\nThe string is Palindrome"; else cout<<"\nThe string is not Palindrome"; return 0; }
Output
Enter a string:saas
The string is Palindrome
use i<len/2 in 2nd for loop is doubtful.
i could not understan this logic…
A string is palindrome if first half is equal to second half. Therefor the 2nd loop run till half of the length of string.
yes i too have the same doubt of using i>l/2
Does it works if you simply cin>>a ??
Nice program
for(len=0;a[len]!=’’;++len);
” this symbol i could not understand.
This if for getting the length of appropriate array. after writing a word or a paragraph the length is pointing at a final index. which is the length of an array.
to many errors!!!!!
Dear Sir,
Can you explain me ….brief about logic.
no
How can I write a c++ program that print the ff…
5
4 5 4
3 4 5 4 3
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
please help me…
Thanks!
#include
int main()
{
int i,j,k;
for(i = 5; i >= 1; i–)
{
for(j = i; j<5; j++)
{
std::cout <=i; k–)
{
std::cout << k;
}
std::cout<<std::endl;
}
return 0;
}
Thanks for the reply.
I wonder if you see it and reply again.
But, It is somehow tricky if the output is
5
4 5 4
3 4 5 4 3
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
I wonder if you do it in c++.
Thanks anyways.
this prgm hv many errors !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sir how can i make the output like this
*
**
**
***
***
***
****
****
****
****
*****
*****
*****
*****
***** and
1
23
456
78910
3 fir loop lagne vale hai bhai uske liye
my compiler is giving problem in first for loop for(len=0;a[len]!=’’;++len); can you plz tell me what should i do to remove that problem.
There is a little mistake in code change a[len]!=’’ to a[len]!=’\0′