write program for palindrome
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Difference between overloading vs. Overriding
What is #include c++?
What is an action class?
how many rounds and wt type of questios ask in the written test for first round 2. tech. round 3. and futher rounds
What is the purpose of template?
Can you Mention some Application of C/C++?
Explain the difference between c & c++?
Write a struct time where integer m, h, s are its members?
What data encapsulation is in c++?
How are virtual functions implemented in c++?
What is stack unwinding?
What is the full form of ios?