Advertisement
lammac

Kiểm tra một số có phải là số nguyên tố

Apr 3rd, 2020
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.28 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main(){
  4.     int n;
  5.     scanf("%d", &n);
  6.     if(n<2){
  7.         printf("0");
  8.         return 0;
  9.     }
  10.     int count = 0;
  11.     for(int i = 2; i <= sqrt(n); i++){
  12.         if( n%i == 0 ){
  13.             count++;
  14.         }
  15.     }
  16.     if(count==0){
  17.         printf("1");
  18.     }
  19.     else{
  20.         printf("0");
  21.     }
  22.    
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement