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

Wednesday, February 17, 2010

WAP to print all prime numbers, ending with digit '7', in descending order.


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

void main()
{
int start, end , flag = 0, r ;

cout<<" \n Enter the number to start with :";
cin>> start;

cout<<" \n Enter the number to end with :";
cin>>end;

if(start>end)
{
cout<<"\n Invalid Input.";
getch();
exit(1);
}

clrscr();
cout<<"\n The Series :\n ";

for(int i = end ; i>=start ; i--)
{
flag = 0;

for(int j = 2; j< = i-1 ; j++)
{
r = i%j;
if(r == 0)
{
flag = 1;

}
}

if(flag == 0)
{
if(i%10 == 7)
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.