Lab Work 2: Strange Number

Write a C++ Program to find all the strange number between 1 and 10,000. Use C++ Abstraction.


Hint:

We define "strange" numbers in the following way:
  • All strange numbers are prime.
     
  • Every single digit prime number is strange. 
     
  • A number with two or more digits is strange if, and only if, the two numbers obtained from it, by removing either its first or its last digit, are also strange.

11 comments:

  1. Md Raihan Molla
    ID : 201910061 CSE 60th


    #include
    using namespace std;
    class strange
    {
    public:
    int n,i,r,p,j,k;

    void checked()
    {
    cout<<"All the strange number between 1 to 10,000 is given below :"<<endl;

    for(i=1;i<=10000;i++)
    {
    p=1;
    r=i;

    for(k=2;k<=r/2;k++)
    {
    if (r%k==0)
    {
    p=0;
    break;
    }
    }

    if (p==0)
    continue;

    n=i;

    for(j=0;n!=0;j++)
    {

    r=n%10;

    if(r==0)
    {
    p=0;
    break;
    }

    for(k=2;k<=r/2;k++)
    {

    if (r%k==0)
    {
    p=0;
    break;
    }

    }


    if(p==1)
    n=n/10;

    else
    break;

    }

    if(p==1)
    cout<<i<<endl;


    }
    cout<<endl<<"The End "<<endl;
    }

    };

    int main()
    {
    strange a;
    a.checked();
    }

    ReplyDelete
  2. Md.Alamin Hosen
    Id.201910261
    Batch.60th
    //Write a C++ Program to find all the strange number between 1 and 10,000. Use C++ Abstraction.
    #include
    using namespace std;
    class B
    {
    public:
    int n,i,x,y,j,k;

    void checked()
    {

    for(i=1; i<=10000; i++)
    {
    y=1;
    x=i;

    for(k=2; k<=x/2; k++)
    {
    if (x%k==0)
    {
    y=0;
    break;
    }
    }

    if (y==0)
    continue;

    n=i;

    for(j=0; n!=0; j++)
    {

    x=n%10;

    if(x==0)
    {
    y=0;
    break;
    }

    for(k=2; k<=x/2; k++)
    {

    if (x%k==0)
    {
    y=0;
    break;
    }

    }


    if(y==1)
    n=n/10;

    else
    break;

    }

    if(y==1)
    cout<<i<<endl;


    }
    cout<<"end";
    }

    };

    int main()
    {
    B a;
    a.checked();
    }

    ReplyDelete
  3. Md. Aminul Islam Anik
    ID:201910353 CSE 60th

    #include
    using namespace std;
    class strange
    {
    public:
    int n,i,r,p,j,k;

    void checked()
    {
    cout<<"All the strange number between 1 to 10,000 is given below :"<<endl;

    for(i=1;i<=10000;i++)
    {
    p=1;
    r=i;

    for(k=2;k<=r/2;k++)
    {
    if (r%k==0)
    {
    p=0;
    break;
    }
    }

    if (p==0)
    continue;

    n=i;

    for(j=0;n!=0;j++)
    {

    r=n%10;

    if(r==0)
    {
    p=0;
    break;
    }

    for(k=2;k<=r/2;k++)
    {

    if (r%k==0)
    {
    p=0;
    break;
    }

    }


    if(p==1)
    n=n/10;

    else
    break;

    }

    if(p==1)
    cout<<i<<endl;


    }
    cout<<endl<<"The End "<<endl;
    }

    };

    int main()
    {
    strange a;
    a.checked();
    }

    ReplyDelete
  4. MD:Rabiul Auwal
    id:201911082 CSE 60th

    #include
    using namespace std;
    class strange
    {
    public:
    int f,i,b,p,u,k;

    void checked()
    {
    cout<<"All the strange number between 1 to 10,000 is given below :"<<endl;

    for(i=1;i<=10000;i++)
    {
    p=1;
    b=i;

    for(k=2;k<=b/2;k++)
    {
    if (b%k==0)
    {
    p=0;
    break;
    }
    }

    if (p==0)
    continue;

    f=i;

    for(u=0;f!=0;u++)
    {

    b=f%10;

    if(b==0)
    {
    p=0;
    break;
    }

    for(k=2;k<=b/2;k++)
    {

    if (b%k==0)
    {
    p=0;
    break;
    }

    }


    if(p==1)
    f=f/10;

    else
    break;

    }

    if(p==1)
    cout<<i<<endl;


    }
    cout<<endl<<"The End "<<endl;
    }

    };

    int main()
    {
    strange a;
    a.checked();
    }

    ReplyDelete
  5. //Md.Rabbi Islam Fahim
    //Id:201910914
    //Batch:60th
    //(: :)





    #include
    #include
    using namespace std;
    class r
    {
    public:
    int n,i,r,c,l,k;

    int att()
    {
    cout<< "All The Strange Number 1 To 10000 : " <<endl;

    for(l=1;l<=10000;l++)
    {
    c=1;
    n=l;

    for(i=2;i<=n/2;i++)
    {
    if (n%i==0)
    {
    c=0;
    break;
    }
    }

    if (c==0)

    continue;


    r=l;


    for(k=0;r!=0;k++)
    {

    n=r%10;


    if(n==0)
    {
    c=0;
    break;
    }

    for(i=2;i<=n/2;i++)
    {

    if (n%i==0)
    {
    c=0;
    break;
    }

    }


    if(c==1)
    r=r/10;

    else
    break;

    }

    if(c==1)
    cout<<l<<endl;


    }
    cout<< "\nThank You So Much (:" <<endl;
    getch();

    }

    };

    int main()
    {
    r obj;
    obj.att();
    }

    ReplyDelete
  6. Robin Ahmed
    Id:201910109

    #include
    using namespace std;
    class strange
    {
    public:
    int n,i,r,p,j,k;

    void checked()
    {


    for(i=1;i<=10000;i++)
    {
    p=1;
    r=i;

    for(k=2;k<=r/2;k++)
    {
    if (r%k==0)
    {
    p=0;
    break;
    }
    }

    if (p==0)
    continue;

    n=i;

    for(j=0;n!=0;j++)
    {

    r=n%10;

    if(r==0)
    {
    p=0;
    break;
    }

    for(k=2;k<=r/2;k++)
    {

    if (r%k==0)
    {
    p=0;
    break;
    }

    }


    if(p==1)
    n=n/10;

    else
    break;

    }

    if(p==1)
    cout<<i<<endl;


    }
    cout<<endl<<"End "<<endl;
    }

    };

    int main()
    {
    strange a;
    a.checked();
    }

    ReplyDelete
  7. //Eva
    //Id:201910819
    //Batch:60th
    //(: 🙂
    #include

    using namespace std;
    class r
    {
    public:
    int n,i,r,c,l,k;

    int att()
    {

    for(l=1;l<=10000;l++)
    {
    c=1;
    n=l;

    for(i=2;i<=n/2;i++)
    {
    if (n%i==0)
    {
    c=0;
    break;
    }
    }

    if (c==0)

    continue;


    r=l;


    for(k=0;r!=0;k++)
    {

    n=r%10;


    if(n==0)
    {
    c=0;
    break;
    }

    for(i=2;i<=n/2;i++)
    {

    if (n%i==0)
    {
    c=0;
    break;
    }

    }


    if(c==1)
    r=r/10;

    else
    break;

    }

    if(c==1)
    cout<<l<<endl;


    }



    }

    };

    int main()
    {
    r obj;
    obj.att();
    }

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete

  9. Name: Towhidul Islam
    ID:201811105,Sec-C
    Batch-57th
    #include
    using namespace std;
    class strange
    {
    public:
    int a,i,b,f,j,s;

    void checked()
    {
    cout<<"All the strange number between 1 to 10,000 is given below :"<<endl;

    for(i=1;i<=10000;i++)
    {
    f=1;
    b=i;

    for(s=2;s<=b/2;s++)
    {
    if (b%s==0)
    {
    f=0;
    break;
    }
    }

    if (f==0)
    continue;

    a=i;

    for(j=0;a!=0;j++)
    {

    b=a%10;

    if(b==0)
    {
    f=0;
    break;
    }

    for(s=2;s<=b/2;s++)
    {

    if (b%s==0)
    {
    f=0;
    break;
    }

    }


    if(f==1)
    a=a/10;

    else
    break;

    }

    if(f==1)
    cout<<i<<endl;


    }
    cout<<endl<<"The End "<<endl;
    }

    };

    int main()
    {
    strange a;
    a.checked();
    }

    ReplyDelete
  10. Name:Mohima Akter
    ID-201811112,Sec-C
    Batch-57th

    #include
    using namespace std;
    class strange
    {
    public:
    int m,a,h,i,j,l;

    void checked()
    {
    cout<<"All the strange number between 1 to 10,000 is given below :"<<endl;

    for(i=1;i<=10000;i++)
    {
    h=1;
    a=i;

    for(l=2;l<=a/2;l++)
    {
    if (a%l==0)
    {
    h=0;
    break;
    }
    }

    if (h==0)
    continue;

    m=i;

    for(j=0;m!=0;j++)
    {

    a=m%10;

    if(a==0)
    {
    h=0;
    break;
    }

    for(l=2;l<=a/2;l++)
    {

    if (a%l==0)
    {
    h=0;
    break;
    }

    }


    if(h==1)
    m=m/10;

    else
    break;

    }

    if(h==1)
    cout<<i<<endl;


    }
    cout<<endl<<"The End "<<endl;
    }

    };

    int main()
    {
    strange m;
    m.checked();
    }

    ReplyDelete
  11. Name:Mohammat.ali zinnah
    id: 201910567
    batch:60

    #include
    using namespace std;
    class strange
    {
    public:
    int a,i,b,f,j,s;

    void checked()
    {
    cout<<"All the strange number between 1 to 10,000 is given below :"<<endl;

    for(i=1;i<=10000;i++)
    {
    f=1;
    b=i;

    for(s=2;s<=b/2;s++)
    {
    if (b%s==0)
    {
    f=0;
    break;
    }
    }

    if (f==0)
    continue;

    a=i;

    for(j=0;a!=0;j++)
    {

    b=a%10;

    if(b==0)
    {
    f=0;
    break;
    }

    for(s=2;s<=b/2;s++)
    {

    if (b%s==0)
    {
    f=0;
    break;
    }

    }


    if(f==1)
    a=a/10;

    else
    break;

    }

    if(f==1)
    cout<<i<<endl;


    }
    cout<<endl<<"The End "<<endl;
    }

    };

    int main()
    {
    strange a;
    a.checked();
    }

    ReplyDelete

Comment Here