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

Thursday, March 4, 2010

Print all prime numbers, that end with '1' , in descending order, from 500 to 1


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

cout<< "\n The Prime numbers ending with digit 1 :";
for(int i = 500 ; i >=2 ; i--)
{
flag = 0;
for(int j = 2 ; j <= i-1 ; j++)
{
r = i%j;
if(r == 0)
{
flag = 1;
break;
}
}

if(flag == 0)
{
    if(i%10 == 1)
        cout<< i << "  ";
}
}

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.