Skip to content

Commit

Permalink
完成了isPrime
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitaibel committed Mar 13, 2018
1 parent 21da9f0 commit ac395a5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions level1/p02_isPrime/isPrime_Kitaibel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
long long int n,i;
scanf("%lld",&n);
if(n==1)
{
printf("1不是素数");
exit(0);
}

if(n==2)
{
printf("2是素数");
exit(0);
}

for(i=2;i<sqrt(n)+1;i++)
{
if(n%i==0)
{
printf("%lld不是素数",n);
exit(0);
}
}

printf("%lld是素数",n);
return 0;
}

0 comments on commit ac395a5

Please sign in to comment.