Advertisement
afrinahoque

Whether a number is a prime number or not using function

Jul 6th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include<stdio.h>
  2. void checkNum(n)
  3. {
  4.     int i, count=0;
  5.     for(i=2; i<n; i++)
  6.     {
  7.         if(n%i==0)
  8.         {
  9.             count++;
  10.             break;
  11.         }
  12.     }
  13.     if(count==0)
  14.  
  15.     {
  16.         printf("%d is prime number.\n", n);
  17.     }
  18.  
  19.     else
  20.  
  21.     {
  22.         printf("%d is not prime number.\n", n);
  23.     }
  24.  
  25. }
  26. int main()
  27. {
  28.     int n;
  29.     scanf("%d", &n);
  30.     checkNum(n);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement