Advertisement
Mr_kindle

Right truncable prime number code

Jul 19th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1.  
  2.  
  3. /*
  4.     Name: righttruncable.c
  5.     Copyright:
  6.     Author: Mr.Kindle
  7.     Date: 08-12-22 22:22
  8.     Description: This code print all righttruncable prime numbers between 100 & 999.
  9.  
  10. youtube: https://youtu.be/HuSXkh0IzDU
  11. */
  12. #include<stdio.h>
  13. int isprime(int );
  14. int checkzero(int);
  15. int isrighttruncable (int);
  16.  
  17. int main()
  18. {
  19.     int i,k=0;
  20.     for (i=100;i<=999;i++)
  21.          { if(isprime(i)==1 && checkzero(i)==1)
  22.                { if (isrighttruncable(i)==1)
  23.                       {printf("%d ",i);
  24.                             k++;
  25.                         }
  26.             }
  27.          }
  28.         printf("\n\nTotal number of right-truncable prime number between 100 and 999 = %d\n",k);
  29.     return 0;
  30. }//main
  31.  
  32. int isprime (int n)
  33. { int i;
  34.     for (i=2;i<=n/2;i++)
  35.         if(n%i==0)
  36.            return 0;
  37.        if(n==1)
  38.             return 0;
  39.         else    
  40.            return 1;
  41. }//isprime
  42.  
  43. int checkzero (int n)
  44. {  if( n%100/10==0 || n%10==0)
  45.        return 0;
  46.     else
  47.        return 1;
  48. }//checkzero
  49.  
  50.  
  51. int isrighttruncable (int n)
  52. { if(isprime(n/10)==1 && isprime(n/100)==1)
  53.      return 1;
  54.     else
  55.        return 0;
  56. }//isrighttruncable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement