bsc

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

root / semester_1 / practice-c / pc006.c

pc006.c (896B)


      1 /* Prime number check */
      2 
      3 #include <stdio.h>
      4 #include <math.h>
      5 
      6 int main()
      7 {
      8     int num, i, temp;
      9     printf("Enter the number : ");
     10     if(scanf("%d", &num) != 1) {
     11         printf("Only postive number allowed.");
     12         return 1;
     13     }
     14     if(num <= 0) {
     15         printf("\nOnly potive number are allowed.");
     16         return 1;
     17     }
     18     if(num == 1) {
     19         printf("\nInput 1 is not a prime number.");
     20         return 0;
     21     }
     22     if(num == 2) {
     23         printf("\nInput 2 is a prime number.");
     24         return 0;
     25     }
     26     if(num % 2 == 0) {
     27         printf("\nInput %d is not a prime number.", num);
     28         return 0;
     29     }
     30     temp = (int)sqrt(num);
     31     for (i = 3; i <= temp; i += 2)
     32     {
     33         if (num % i == 0)
     34         {
     35             printf("\nInput %d is not a prime number.", num);
     36             return 0;
     37         }
     38     }
     39     printf("\nInput %d is a prime number.", num);
     40     return 0;
     41 }
© 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