bsc

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

pc006.c (1087B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 12 Dec 2025
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Prime number check */
      9 
     10 #include <stdio.h>
     11 #include <math.h>
     12 
     13 int main()
     14 {
     15     int num, i, temp;
     16     printf("Enter the number : ");
     17     if(scanf("%d", &num) != 1) {
     18         printf("Only postive number allowed.");
     19         return 1;
     20     }
     21     if(num <= 0) {
     22         printf("\nOnly potive number are allowed.");
     23         return 1;
     24     }
     25     if(num == 1) {
     26         printf("\nInput 1 is not a prime number.");
     27         return 0;
     28     }
     29     if(num == 2) {
     30         printf("\nInput 2 is a prime number.");
     31         return 0;
     32     }
     33     if(num % 2 == 0) {
     34         printf("\nInput %d is not a prime number.", num);
     35         return 0;
     36     }
     37     temp = (int)sqrt(num);
     38     for (i = 3; i <= temp; i += 2)
     39     {
     40         if (num % i == 0)
     41         {
     42             printf("\nInput %d is not a prime number.", num);
     43             return 0;
     44         }
     45     }
     46     printf("\nInput %d is a prime number.", num);
     47     return 0;
     48 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror