Advertisement
18126

Day3(ex1)

Jul 7th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int checkPrime(int n, int c) {
  6.     if(c > 9) {
  7.         return 1;
  8.     }
  9.     if(n % c == 0) {
  10.         return 0;
  11.     }
  12.     return checkPrime(n, c+1);
  13. }
  14.  
  15. int main() {
  16.     int n;
  17.     printf("Enter number to be checked: \n");
  18.     scanf("%d", &n);
  19.     if(n == 1) {
  20.         printf("1 is not a prime number. :D");
  21.         return EXIT_SUCCESS;
  22.     } else if(n == 2) {
  23.         printf("2 is a prime number.");
  24.     } else if(n == 3) {
  25.         printf("3 is a prime number.");
  26.     }
  27.     int counter = 2;
  28.     int isPrime = checkPrime(n, counter);
  29.     if(isPrime == 1) {
  30.         printf("%d is a prime number.", n);
  31.     } else {
  32.         printf("%d is not a prime number.", n);
  33.     }
  34.     return EXIT_SUCCESS;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement