Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: lefttruncable.c
- Copyright:
- Author: Mr.Kindle
- Date: 08-12-22 22:22
- Description: This code print all lefttruncable prime numbers between 100 & 999.
- youtube: https://youtu.be/HuSXkh0IzDU
- */
- #include<stdio.h>
- int isprime(int );
- int checkzero(int);
- int isrighttruncable (int);
- int main()
- {
- int i,k=0;
- for (i=100;i<=999;i++)
- { if(isprime(i)==1 && checkzero(i)==1)
- { if (isrighttruncable(i)==1)
- {printf("%d ",i);
- k++;
- }
- }
- }
- printf("\n\nTotal number of right-truncable prime number between 100 and 999 = %d\n",k);
- return 0;
- }//main
- int isprime (int n)
- { int i;
- for (i=2;i<=n/2;i++)
- if(n%i==0)
- return 0;
- if(n==1)
- return 0;
- else
- return 1;
- }//isprime
- int checkzero (int n)
- { if( n%100/10==0 || n%10==0)
- return 0;
- else
- return 1;
- }//checkzero
- int isrighttruncable (int n)
- { if(isprime(n%100)==1 && isprime(n%10)==1)
- return 1;
- else
- return 0;
- }//isrighttruncable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement