IP-04.c (1102B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 03 Jan 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a function to check whether a number is prime or not. Use the same function to 9 generate all prime numbers less than 100. */ 10 11 #include <stdio.h> 12 #include <math.h> 13 14 int isPrime(int); 15 16 int main() 17 { 18 int n, i; 19 printf("Enter the number: "); 20 scanf("%d", &n); 21 if (isPrime(n)) 22 { 23 printf("\nInput %d is a Prime Number.", n); 24 } 25 else 26 { 27 printf("\nInput %d is not a Prime Number.", n); 28 } 29 printf("\nPrime Numbers less than 100:"); 30 for (i = 1; i < 100; i++) 31 { 32 if (isPrime(i)) 33 { 34 printf(" %d", i); 35 } 36 } 37 return 0; 38 } 39 40 int isPrime(int n) 41 { 42 if (n <= 1) 43 return 0; 44 if (n == 2) 45 return 1; 46 if (n % 2 == 0) 47 return 0; 48 49 int temp = (int)sqrt(n); 50 int i; 51 for (i = 3; i <= temp; i += 2) 52 { 53 if (n % i == 0) 54 { 55 return 0; 56 } 57 } 58 return 1; 59 }