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