fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. int num, i, is_prime = 1;
  6.  
  7. // Asking user to input a number
  8. printf("Enter a positive integer: ");
  9. scanf("%d", &num);
  10.  
  11. if (num <= 1) {
  12. is_prime = 0; // Numbers less than or equal to 1 are not prime
  13. } else {
  14. // Loop to check divisibility
  15. for (i = 2; i <= sqrt(num); i++) {
  16. if (num % i == 0) {
  17. is_prime = 0; // If divisible, not prime
  18. break;
  19. }
  20. }
  21. }
  22.  
  23. if (is_prime) {
  24. printf("%d is a prime number.\n", num);
  25. } else {
  26. printf("%d is not a prime number.\n", num);
  27. }
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Enter a positive integer: 32765 is not a prime number.