Showing posts with label palindrome. Show all posts
Showing posts with label palindrome. Show all posts

Friday, February 13, 2015

Java program to check whether a given number is palindrome or not

Java program to check whether a given number is palindrome or not

class Palindrome
{
public static void main(String...s)
{
int n,m,rev=0,i;
n=Integer.parseInt(s[0]);
m=n;

while(n!=0)
{
i=n%10;
rev=(rev*10)+i;
n/=10;
}

if(m==rev)
System.out.println("
Number is 


palindrome");
else
System.out.println("
Number is not 


palindrome");
}
}
Read more »

Wednesday, February 11, 2015

C program to check whether given string is palindrome or not


C program to check whether given string is palindrome or not

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
int i,j,flag=1,len;
char str[50];
clrscr();
printf("Enter any string:");
gets(str);
len=strlen(str);

for(i=0,j=len-1;i<len/2;++i,--j)
if(str[i]!=str[j])
{
flag=0;
break;
}
if(flag)
printf("String is palindrome");
else
printf("String is not palindrome");
getch();
}
Read more »