write program for palindrome

Answers were Sorted based on User's Feedback



write program for palindrome..

Answer / ramya

#include<stdio.h>
#include<conio.h>
void main()
{
string s1,s2;
printf("Enter the string:");
scanf("%s",s1);
s2=strrev(s1);
if(s1==s2)
{
printf("the given string is palindrome");
}
else
printf("the given string is not palindrome");
}

Is This Answer Correct ?    0 Yes 2 No

write program for palindrome..

Answer / abhinav garg

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
int palindrome(char str[30],int len);
void main()
{ clrscr();
char str[50];
int len,a;
cout<<"Enter a string:";
gets(str);
len=strlen(str);
cout<<"\nLength of the string=>"<<len;
a=palindrome(str,len);
if(a==1)
cout<<"\n String is palindrome...";
else
cout<<"\n String is not a palindrome...";
getch();
}

int palindrome( char str[30],int len)
{ int flag=0,i;
for( i=0;i<len/2;i++)
{
if(str[i]==str[len-i])
flag=1;
}
return flag;
}

Is This Answer Correct ?    10 Yes 13 No

write program for palindrome..

Answer / noor alam khan

#include<iostream.h>
#include<conio.h>

main()
{
int n, reverse = 0, temp;

cout<<"Enter a number to check if it is a palindrome or
not\n"<<endl;
cin>>n;

temp = n;

while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}

if ( n == reverse )
cout<<n<<" is a palindrome number \n"<<endl;
else
cout<<n<<"is not a palindrome number"<<endl;

return 0;
}

Is This Answer Correct ?    0 Yes 3 No

write program for palindrome..

Answer / amrutha

String s1=args[0];
String s2="";

for(int i=0; i<s1.length(); i++)
{
s2=s2+charAt(i);
}
if(s1.equals(s2))
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");

Is This Answer Correct ?    168 Yes 173 No

write program for palindrome..

Answer / surya

#include<stdio.h>
#include<conio.h>
void main()
{
int n,rev=0,r;
clrscr();
printf("enter any no");
scanf("%d",&n);
m=n;
while(n>0)
{
r=n%10;
rev=rev*10+r;
n=n/10;
}
printf("reverse of the number is %d",rev);

}

Is This Answer Correct ?    14 Yes 19 No

write program for palindrome..

Answer / md. arif shahmim

#include<stdio.h>
#include<string.h>
#define size 26

void main()
{
char strsrc[size];
char strtmp[size];

clrscr();
printf("\n Enter String:= "); gets(strsrc);

strcpy(strtmp,strsrc);
strrev(strtmp);

if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string \"%s\" ispalindrome",strsrc);
else
printf("\n Entered string \"%s\" is not
palindrome",strsrc);
getch();
}

Is This Answer Correct ?    16 Yes 23 No

write program for palindrome..

Answer / aishwarya

/*using pointers*/
main()
{
char str[]="MalyalaM";
char *s;
s=str+8;
while(s>=str)
{
printf("%c",*s);
s--;
}
}

Is This Answer Correct ?    10 Yes 18 No

write program for palindrome..

Answer / chander singh

#include<stdio.h>
#include<conio.h>
void main()
{
int r,n,k=0,l;
printf("\n\t\tENTER THE NUMBER \t");
scanf("%d",&n);
l==n;
while(n>0)
{
r=n%10;
n=n/10;
k=k*10+r;
printf("%d",r); //
}
if(r==m)
printf("\n\t\tpalindrome");
else
printf("\n\t\t not palindrome");
getch();
}

Is This Answer Correct ?    16 Yes 25 No

write program for palindrome..

Answer / vineet

#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;

#define FALSE 0
#define TRUE 1

int power(int num, int pow)
{
int finalNum = 1;
while(pow)
{
finalNum = finalNum*num;
pow--;
}
return finalNum;
}


bool IsPalindrome1(int n)
{
bool retVal = TRUE;
int indx=0, i=1, a=0;
int arr[10]={0,};

if(0 == (n%10))
return FALSE;

while(n)
{
a=(n%(power(10,i)))/power(10, (i-1));
n = n-(a*power(10,(i-1)));
arr[indx]=a;
indx++;
i++;
}
i--;
for(int j=0;j<=(i/2);j++)
{
if(arr[j] == arr[i-j-1])
retVal = retVal & TRUE;
else
retVal = retVal & FALSE;
}
return retVal;
}


void main()
{
int n=0;
bool b=FALSE;
cout<<" Enter a number to check whether it is a
palindrome or not:";
cin>>n;
b = IsPalindrome2(n);
if(TRUE == b)
cout<<"The number is palindrome"<<endl;
else
cout<<"The number is NOT a
palindrome"<<endl;
getche();
}

Is This Answer Correct ?    18 Yes 28 No

write program for palindrome..

Answer / sahil

answer #9 is correct.

Just use long int instead of int.

and use %ld instead of %d.

I hv tested it.

It works 100%

Is This Answer Correct ?    28 Yes 40 No

Post New Answer

More C++ General Interview Questions

difference between c and c++?

38 Answers   Cognizant, IBM, Infosys, Oracle, Sarva Shiksha Abhiyan, Wipro,


Explain the difference between abstract class and interface in c++?

0 Answers  


Define what is constructor?

0 Answers  


What is a linked list in c++?

0 Answers  


What does the following code do: int c=0; cout< a) Undefined *Updated* b) 01 c) 00

0 Answers  






What is a responder chain?

0 Answers  


Write a program in C++ for Fibonacci series

0 Answers   Axtria, ITC Indian Tobacco Company,


what are function pointers?

0 Answers  


What is the function to call to turn an ascii string into a long?

0 Answers  


What are stacks? Give an example where they are useful.

0 Answers  


What is c++ in english?

0 Answers  


what is oops and list its features in c++?

0 Answers  


Categories