Program to determine whether a given number is a twisted prime number

A number is called a twisted prime number if it is a prime number and reverse of this number is also a prime number.

Examples: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79

The algorithm to check whether a given number is a twisted prime number is given below.

Algorithm

  • STEP 1: START
  • STEP 2: DEFINE n, reverse, flag
  • STEP 3: SET sum = 0
  • STEP 4: ENTER n
  • STEP 5: REPEAT STEP 6 to 8 UNTIL (n!=0)
  • STEP 6: reverse = n%10
  • STEP 7: sum = sum*10 + reverse
  • STEP 8: n = n/10
  • STEP 9: SET flag =0
  • STEP 10: REPEAT STEP 11 UNTIL j<=sum/2
  • STEP 11: if(sum%j)==0
    then
    set flag = 1
    break
  • STEP 12: if(flag==0)
    then PRINT "yes"
    else
    PRINT "no"
  • STEP 13: END

Java Program

Output:

Enter the prime number?
43
Not Twisted Prime

Python Program

Output:

Enter the prime number?
13
Twisted Prime

C Program

Output:

Enter the prime number?
11
Twisted Prime

C# program

Output:

            Enter the prime number?
            13
            Twisted Prime

PHP Program

Output:

             Enter the prime number?
             17
             Twisted Prime
Next Topic#




Latest Courses