-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprime-numbers.c
33 lines (31 loc) · 988 Bytes
/
prime-numbers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int limit;
printf("Determine a limit : ");
scanf("%d",&limit); //Get the limit from user !
clock_t time;
time = clock(); // start timer
int k=0;
printf("2 \n3 \n5 \n"); // add missing numbers
for(int i=2 ;i<limit ; i++){ // Start to search
k=i/2; // For optimization divide i in half !
for(int j=2; j<k ; j++){ // Check all i if it is prime number !
if(i%j == 0){
break; // if i is not prime number break this loop !
}
else{
if(j == k-1){
printf("%d \n",i); // SHow if i is prime number
break; //if it is prime number break this loop !
}
}
}
}
time = clock() - time; // find the elapsed time !
double time_taken = ((double)time) / CLOCKS_PER_SEC;
printf("\n Geçen Süre %f",time_taken);
return 0;
}