bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / tuition-c / APC-PRAC-022.c

APC-PRAC-022.c (1272B)


      1 /* Write a program to accept a number and check whether the number is twisted prime or not */
      2 // File Name - amit0711202504.c (LAB), APC-PRAC-022.c (Local)
      3 
      4 // This code has not been compiled.
      5 // If you find any issues, please create a new issue on GitHub regarding them.
      6 // Go to this link to create a new issue: https://github.com/notamitgamer/bsc/issues
      7 
      8 #include <stdio.h>
      9 #include <math.h>
     10 #include <stdbool.h>
     11 
     12 bool checkPrime(int num)
     13 {
     14     if (num < 2)
     15         return false;
     16     if (num == 2)
     17         return true;
     18     if (num % 2 == 0)
     19         return false;
     20     int limit = (int)sqrt(num);
     21     for (int i = 3; i <= limit; i += 2)
     22         if (num % i == 0)
     23             return false;
     24     return true;
     25 }
     26 
     27 int reverseNumber(int num)
     28 {
     29     int reverse = 0;
     30     while (num > 0)
     31     {
     32         reverse = (reverse * 10) + (num % 10);
     33         num /= 10;
     34     }
     35     return reverse;
     36 }
     37 
     38 int main()
     39 {
     40     int num;
     41     printf("Enter the number : ");
     42     scanf("%d", &num);
     43     if (!checkPrime(num))
     44     {
     45         printf("\nInput %d is not a prime number.", num);
     46         return 0;
     47     }
     48     if (checkPrime(reverseNumber(num)))
     49         printf("\nInput %d is a twisted prime number.", num);
     50     else
     51         printf("\nInput %d is not a twisted prime number.", num);
     52     return 0;
     53 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror