"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Thursday, February 25, 2010

WAP to print all prime numbers between 100 to 500 , that are palindrome.


#include<iostream.h>
#include<conio.h>
void main()
{
int flag,rev;

cout<< "\n The palindrome prime numbers between 100 to 500 are :\n";

for(int n = 100 ; n<=500 ; n ++ )
{
flag = 0;
/* Check Prime number for each n */ 
for(int j = 2; j < = n-1 ; j++)
{
if(n%j == 0)
{
flag = 1;
break;
}
}

rev = 0;

//reverse the number and check palindrome
if(flag == 0)
{
for(int k = n; k >=1 ; k = k/10)
{
rev = rev*10 + k%10;
}

if(rev == n)
cout<< n << " " ;
}

}

getch();

}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.