Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
A digit prime is a prime number whose sum of digits is also prime.
For example the prime number 23 is a digit prime because 2+3=5 and 5 is a prime number. 17 is not a digit prime because 1+7 = 8, and 8 is not a prime number. Write a program to find out the number of digit primes within a certain range less than 1000000.and also print the Mth digit prime number between the range.





C#
#include<stdio.h>

int main()
{
   int n, i = 3, count, c;

   printf("Enter the number of prime numbers required\n");
   scanf("%d",&n);

   if ( n >= 1 )
   {
      printf("First %d prime numbers are :\n",n);
      printf("2\n");
   }

   for ( count = 2 ; count <= n ;  )
   {
      for ( c = 2 ; c <= i - 1 ; c++ )
      {
         if ( i%c == 0 )
            break;
      }
      if ( c == i )
      {
         printf("%d\n",i);
         count++;
      }
      i++;
   }

   return 0;
}
Posted

1 solution

See the answer in this link for the IsPrime function - C - determine if a number is prime[^]
I'm sure you can take it from there.
 
Share this answer
 
Comments
Member 10208229 14-Aug-13 1:21am    
please edit the program i have uploaded and upload it back. please
JackDingler 14-Aug-13 11:01am    
No
JackDingler 14-Aug-13 11:39am    
You won't learn anything if we do it for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900