Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
Hepper123 committed Mar 9, 2021
1 parent 03705b5 commit 31de5e3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions level1/p05_allPrimes/allPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <time.h>

int main()
{
int i = 2;
int IsPrime = 1;
clock_t start, finish;
double Total_time;
start = clock();
for (i = 2; i <= 1000; i++)
{
IsPrime = 1;
for (int j = 2; j <= i / 2; j++)
{
if (i % j == 0)
{
IsPrime = 0;
break;
}
}
if (IsPrime == 1)
{
printf("%d\n", i);
}
}
finish = clock();
Total_time = (double)(finish - start) / CLOCKS_PER_SEC;
printf("%f seconds\n", Total_time);
}

0 comments on commit 31de5e3

Please sign in to comment.