Skip to content
DragonlordWarlock.com

DragonlordWarlock.com

Home of the Dragonlord Warlock/Norin Nightfire

  • Home
  • About Me
  • Poetry
  • Photos
  • Programming
  • Wallpaper
  • Norin Nightfire
  • Privacy Policy
  • Home
  • C++ Prime Numbers

C++ Prime Numbers

Posted on 2016-01-10 By Administrator
c++, programming

#include <stdio.h>
#include <time.h>

using namespace std;

bool isPrime(long n)
{
	long i, m;
	m = n / 2;
	if(n % 2==0)
		return false;
	else for(i=3; i<m; i+=2)
		if(n % i==0)
			return false;
	return true;
}

int main()
{
	long j;
	clock_t tStart = clock();
	for(j=1;j<1000000;j++)
		if(isPrime(j))
			printf("%ld\n", j);
	printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
	return 0;
}

 

Post navigation

❮ Previous Post: Chloe
Next Post: To Chloe 2016 ❯

You may also like

c++
Fractal Tree C++ Logo Output
2012-12-11
Chlo
Chloe
2016-01-03
linux
Converting webp to PNG with a bash script to make life easier.
2014-10-01
programming
A Tree in Logo
2012-10-30

Archives

Categories

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Advert

  • Facebook

Copyright © 2026 DragonlordWarlock.com.

Theme: Oceanly News Dark by ScriptsTown