Pages

Custom Search
Showing posts with label prime. Show all posts
Showing posts with label prime. Show all posts

Tuesday, October 11, 2011

Program to check whether the entered number is superprime or not.


//For a number to be a superprime number the first condition is that it should be a prime number. If the number is a prime number, then for it to become superprime the digits in the prime number should also be prime.
For ex: 19 is a prime number; 1 is a prime but 9 is not a prime. Hence 19 is not a superprime number.
            13 is a prime number; 1 and 3 both are prime numbers. Hence 13 is a superprime number.

#include <stdio.h>
#include <conio.h>

void superprime(int *p);

int main()
{
        int num;
        printf("\nEnter an integer number: ");
        scanf("%d", &num);
        superprime(&num);
        getch();
}
void superprime(int *p)
{
        int a, digit, d=2, flag=1, f=1, t;
        t=*p;

        while(d<*p)
        {
                if((*p%d)==0)
                {
                        flag=0;
                        break;
                }
                d++;
         }
                if(flag==1)
                {
                        f=1;
                        while(t>0)
                        {
                                a=2;

                                digit=t%10;
                                while(a<digit)
                                {
                                         if((digit%a)==0)
                                         {
                                                f=0;
                                                break;
                                         }
                                         a++;
                                }
                                t=t/10;
                        }
                 }

        if(f==1&&flag==1)
                printf("\nGiven number is superprime\n");
        else if(flag==0)
                printf("\nGiven number is not prime\n");
        else if(f==0&&flag==1)
                printf("\nGiven number is prime but not superprime");
        else
                printf("\nGiven number is not prime\n");
        return;
}

SAMPLE OUTPUT:



Custom Search