bsc

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

assignment-p-01.c (1029B)


      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 /* Write a C program that includes a user-defined function named isPrime with the signature 
      9 int isPrime(int num); The function should take an integer as a parameter and return 1 if 
     10 the number is prime and 0 otherwise. */
     11 
     12 #include <stdio.h>
     13 #include <math.h>
     14 
     15 int isPrime(int);
     16 
     17 int main()
     18 {
     19     int n;
     20     printf("Enter the number: ");
     21     scanf("%d", &n);
     22 
     23     if (isPrime(n))
     24     {
     25         printf("\nInput %d is a Prime Number.", n);
     26     }
     27     else
     28     {
     29         printf("\nInput %d is not a Prime Number.", n);
     30     }
     31 
     32     return 0;
     33 }
     34 
     35 int isPrime(int n)
     36 {
     37     if (n <= 1)
     38         return 0;
     39     if (n == 2)
     40         return 1;
     41     if (n % 2 == 0)
     42         return 0;
     43 
     44     int temp = (int)sqrt(n);
     45     int i;
     46     for (i = 3; i <= temp; i += 2)
     47     {
     48         if (n % i == 0)
     49         {
     50             return 0;
     51         }
     52     }
     53     return 1;
     54 }
© 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