Advertisement
PROFESSOR_AIH

Prime Number

Apr 16th, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5.     int num,i,tcase,m,count=0,z;
  6.     scanf("%d",&tcase);
  7.     for(m=1; m<=tcase; m++)
  8.     {
  9.         scanf("%d",&num);
  10.         if(num==1)
  11.         {
  12.             printf("%d nao eh primo\n",num);
  13.             continue;
  14.         }
  15.         z=sqrt(num);
  16.         for(i=2; i<=z; i++)
  17.         {
  18.             if(num%i==0)
  19.             {
  20.                 count++;
  21.                 break;
  22.             }
  23.         }
  24.         if(count==0)
  25.             printf("%d eh primo\n",num);
  26.         else
  27.             printf("%d nao eh primo\n",num);
  28.         count=0;
  29.         z=0;
  30.     }
  31.  
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement