Strange Number

1.Write a C program to Print the Strange Numbers Between 1 and 100000.

main()
{
int a, b, c, n, temp, J;

printf("The Strange Numbers are:\n\t\t");
for(a=1;a<=100000;a++)
{
c=1;
for(b=2;b<=a/2;b++)
{
if(a%b==0)
{
c=0;
break;
}
}
if(c==1)
{
temp=a;
while(temp>0) //starting the loop for extract the number
{
J=temp%10;
n=1;
for(b=2;b<=J/2;b++) //loop for checking the digit whether is it prime or not.
{
if(J%b = =0)
{
n=0;
break;  //skip the 'for loop'
}
}
if((n= =0)||(J= =0))
{
n=0;
break; //skip the 'while loop'
}
temp /=10;
}  //loop for extract finish
if(n= =1)
{
printf("\t%d", a);
}
}
}

getch();
return 0;
}
<< Go to Index Page >>

9 মন্তব্যসমূহ

  1. #include

    main()
    {
    int a, b, c, n, temp, J;

    printf("The Strange Numbers are:\n\t\t");
    for(a=1;a<=100000;a++)
    {
    c=1;
    for(b=2;b<=a/2;b++)
    {
    if(a%b==0)
    {
    c=0;
    break;
    }
    }
    if(c==1)
    {
    temp=a;
    while(temp>0) //starting the loop for extract the number
    {
    J=temp%10;
    n=1;
    for(b=2;b<=J/2;b++) //loop for checking the digit prime or not after extraction
    {
    if(J%b==0)
    {
    n=0;
    break; //skip the 'for loop'
    }
    }
    if((n==0)||(J==0))
    {
    n=0;
    break; //skip the 'while loop'
    }
    temp/=10;
    } //loop for extract finish
    if(n==1)
    {
    printf("\t%d", a);
    }
    }
    }

    getch();
    return 0;
    }

    উত্তরমুছুন
  2. main()
    {

    int i,digit,rem,st=1;
    printf("\n Enter number for check if it is strange or not: ");
    scanf("%d",&digit);

    while(digit!=0)
    {
    rem=digit%10;
    digit/=10;
    for(i=2;i<rem;i++)
    {
    if(rem%i==0)

    {
    st=0;
    break;
    }

    if(st==1)
    printf("\n This strange number: ",st);
    else
    printf("This is not strange number",st);
    getch();
    return st;

    }




    }
    }

    উত্তরমুছুন
  3. Id:201330499

    #include
    using namespace std;
    class A
    {
    public:
    int a, b, c, n, temp, J;
    int get_inp(int m,int n)
    {
    x=m;
    y=n;
    }
    protected:
    int x;
    int y;
    };
    class B:public A
    {
    public:
    int strange()
    {
    cout<<"The Strange Numbers are:";
    for(a=1;a<=10000;a++)
    {
    c=1;
    for(b=2;b<=a/2;b++)
    {
    if(a%b==0)
    {
    c=0;
    break;
    }
    }
    if(c==1)
    {
    temp=a;
    while(temp>0)
    {
    J=temp%10;
    n=1;
    for(b=2;b<=J/2;b++)
    {
    if(J%b==0)
    {
    n=0;
    break;
    }
    }
    if((n==0)||(J==0))
    {
    n=0;
    break;
    }
    temp/=10;
    }
    if(n==1)
    {
    cout<<a<<endl;
    }
    }
    }
    }
    };
    int main()
    {
    B bb;
    int m=1;
    int n=1000000;
    bb.get_inp(m,n);
    bb.strange();
    return 0;
    }

    উত্তরমুছুন
  4. Summer 2017
    ID#201610042

    Answer to the Question no. 9:

    https://drive.google.com/file/d/0B99eePh0LV8gZTAyNHB3elZCWk0/view?usp=drivesdk

    [Note: the program is acting weirdly. Most of the times it runs fine, but at some points it shows "segmentation faults". I am using gcc compiler for linux.]

    উত্তরমুছুন
  5. Summer 2017
    ID#201610042

    Answer to the Question No. 9:

    https://drive.google.com/file/d/0B99eePh0LV8gdzVod1N3aHBTMWM/view?usp=drivesdk

    This version is fully working...

    উত্তরমুছুন
  6. Summer 2017
    ID#201610042

    Answer according to the definition of strange numbers:

    https://drive.google.com/file/d/0B99eePh0LV8gb0tXOVRwTHhMUUU/view?usp=drivesdk

    Definition of Strange Numbers:

    Any prime number with prime only digits. that is,

    1. the number must be a prime number.
    2. the digits of the number must also be primes.

    উত্তরমুছুন
  7. ID : 201620195
    https://drive.google.com/open?id=0B9K31ospCyFjYmZGTVBUSWt4SDQ

    উত্তরমুছুন
  8. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKSHBUeXhVX09xMDQ

    উত্তরমুছুন
  9. ID 201610456
    MD USUF MIA
    https://drive.google.com/open?id=0B_PIGnOMR0K2RUh0TW5GZ3d4c1k

    উত্তরমুছুন
নবীনতর পূর্বতন