kucheasysa

prime

Jun 6th, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int num, i, isPrime = 1;
  5.  
  6. printf("Enter a positive integer: ");
  7. scanf("%d", &num);
  8.  
  9. if (num <= 1) {
  10. isPrime = 0;
  11. } else {
  12. for (i = 2; i <= num / 2; i++) {
  13. if (num % i == 0) {
  14. isPrime = 0;
  15. break;
  16. }
  17. }
  18. }
  19.  
  20. if (isPrime == 1) {
  21. printf("%d is a prime number\n", num);
  22. } else {
  23. printf("%d is not a prime number\n", num);
  24. }
  25.  
  26. return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment