Advertisement
nahidhasan110

prime number

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