15.9.15

print strange number between 1 and 100000

/* print strange number 1-100000 */

#include<iostream>
#include<conio.h>
using namespace std;
int strange()
{
    int i,j,c,temp,rem,k;
    for(i=1;i<=100000;i++)
    {
        c=1;
        for(j=2;j<=i/2;j++)
        {
            if(i%j==0)
            {
                c=0;
                break;
            }
        }
        if(c==1)
        {
            temp=i;
            while(temp>0)
            {
                rem=temp%10;
                k=1;
                for(j=2;j<=rem/2;j++)
                {
                    if(rem%j==0)
                    {
                        k=0;
                        break;
                    }
                }
                if((k==0)||(rem==0))
                {
                    k=0;
                    break;
                }
                rem/=10;
            }
            if(k==1)
            {
                cout<<i;
            }
        }
    }
    return 0;
}
int main()
{
    cout<<"The Strange number between 1 to 100000 is:"<<endl;
    strange();
    return 0;
}

No comments:

Post a Comment

Comment Here