Advertisement
Programmin-in-Python

C Program to check if the given number is a PRIME NUMBER or not

Jan 9th, 2022
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. int main(){
  5.     bool flag=true;
  6.     int n;
  7.  
  8.     printf("Enter the value of n : ");
  9.     scanf("%d", &n);
  10.  
  11.     for (int i=2; i<n; i++) {
  12.         if (n%i == 0){
  13.             flag = false;
  14.             break;
  15.         }
  16.     }
  17.  
  18.     if(flag==true){
  19.         printf("\n%d is a Prime Number\n", n);
  20.     }else{
  21.         printf("\n%d is NOT a Prime Number\n", n);
  22.     }
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement