Index-1              Index-2              Home Page

Write a program to find the Maximum Strange Numbers Between 1 and 100000



Write a program to find the Maximum Strange Numbers Between 1 and 100000

Hints:
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.
Source Code:
#include<stdio.h>
void main()
{
      int strange, i, c, n, temp, k,large=0;
      printf ("Strange number between 1 to 100000: \n\t");
           for (strange=1; strange <= 100000; strange++)
            {
                       c=1 ;
                       for (i=2; i <= strange/2; i++)
                            {
                                   if(strange % i = = 0)
                                   {
                                          c=0 ;
                                          break ;
                                   }
                              }
                        if (c= =1)
                        {
                              temp = strange ;
                              while (temp>0 )
                                    {
                                            k = temp%10 ;
                                            n = 1 ;
                                            for (i=2; i<=k/2;  i++)
                                                 {
                                                      if( k%i = =0 )
                                                          {
                                                                n=0 ;
                                                                break ;
                                                           }
                                                  }
                                            if ((n= =0) | | (k= =0))
                                                  {
                                                          n=0 ;
                                                          break ;
                                                   }
                                                   temp /=10 ;
                                     }
                              if (n= =1)
                                     {
                                           printf ("\t%d", strange);
                                           large=strange ;
                                     }
                       }
            }
printf ("\n");
printf ("Maximum prime number is: %d",large);
}

4 comments:


  1. int main()
    {
    int n,i=1,sum=0;
    printf("\nThe perfect numbers are:");
    for(n=i;n<=1000;n++)
    {
    i=1;
    sum=0;
    while(i<n)
    {
    if(n%i==0)
    sum=sum+i;
    i++;
    }
    if(sum==n)
    printf("%d\n",n);
    }
    }

    ReplyDelete
  2. #include
    void main()
    {
    int strange, i, c, n, temp, k,large=0;

    printf("Strange number between 1 to 100000:\n\t");
    for(strange=1;strange<=100000;strange++)
    {
    c=1;
    for(i=2;i<=strange/2;i++)
    {
    if(strange%i==0)
    {
    c=0;
    break;
    }
    }
    if(c==1)
    {
    temp=strange;
    while(temp>0)
    {
    k=temp%10;
    n=1;
    for(i=2;i<=k/2;i++)
    {
    if(k%i ==0)
    {
    n=0;
    break;
    }
    }
    if((n==0)||(k==0))
    {
    n=0;
    break;
    }
    temp /=10;
    }
    if(n==1)
    {
    printf("\t%d", strange);
    large=strange;
    }
    }
    }
    printf("\n");
    printf("Maximum prime number is: %d",large);
    }

    ReplyDelete
  3. #include
    using namespace std;

    void prime(int a);


    main()
    {
    int n;
    cin>>n;
    prime(n);

    }

    void prime(int a)
    {
    int i,j,p,sum=0;
    cout<<"prime list : ";
    for(i=1;i<a;i++)
    {
    p=0;
    for(j=2;j<=i/2;j++)
    {
    if(i%j==0)
    {
    p=1;
    break;
    }
    }
    if(p==0)
    {
    sum+=i;
    cout<<i<<",";
    }

    }
    cout<<"\nthe sum is : "<<sum;
    if(sum==a)
    cout<<"\nsum is equal to "<<a<<endl;
    else
    cout<<"\nsum is not equal to " <<a<<endl;

    }

    ReplyDelete
  4. Id:201820505
    batch:58th
    #include
    int main(){
    int n,i,sum;
    int min,max;

    printf("Enter the minimum range-: ");
    scanf("%d",&min);

    printf("Enter the maximum range-: ");
    scanf("%d",&max);

    printf("Perfect numbers in the given range are-: ");
    for(n=min;n<=max;n++){
    i=1;
    sum = 0;

    while(i<n){
    if(n%i==0)
    sum=sum+i;
    i++;
    }

    if(sum==n)
    printf("%d ",n);
    }

    ReplyDelete