The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
c timer prime
Posted by: dave | June 24, 2009 @ 7:27pm
C Code
[
Download
]
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> double timetaken=0; float timer(int T){ static double then=0.0; static double clocks=0; double now,diff; now=(double)clock()/((double)(CLOCKS_PER_SEC)); diff=now-then; if (T <= 0) then=now; return((float)diff); } int main(void) { timetaken=timer(0); int numPrimes = 0; int currentTest = 2; int isPrime = 1; while (numPrimes<10000) { for (int i = 2; i < currentTest-1; i++) { if (currentTest%i == 0){ isPrime = 0; break; } } if (isPrime == 1) { numPrimes = numPrimes + 1; printf("found prime %i %i\n",numPrimes,currentTest); } isPrime = 1; currentTest = currentTest + 1; } timetaken=timer(1); printf("time taken = %f\n",timetaken); system("PAUSE"); return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.54 / 8
141 Votes
http://codebin.yi.org/316
page generated in 0.00 seconds