Advertisement
Mr_kindle

lefttruncablenumber.c

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