All pastes #395112 Raw Edit

Kiryn

public cpp v1 · immutable
·published 2007-03-14 20:25 UTC
rendered paste body
#include "stdafx.h"using namespace std;#ifdef UNICODE#define cout std::wcout#else#define cout std::cout#endifint _tmain(int argc, _TCHAR *argv[]){	long *pprimes = 0;	long trial = 5;	int count = 3;	int found = 0;	int max = 0;	cout << endl		<< "Enter the number of primes you would like (at least 4): ";	cin >> max;	if(max < 4)		max = 4;	pprimes = new long[max];	*pprimes = 2;	*(pprimes + 1) = 3;	*(pprimes + 2) = 5;	do	{		trial += 2;		found = 0;		for(int i = 0; i < count; i++)		{			found = (trial % *(pprimes + i)) == 0;			if(found)				break;		}		if(found == 0)			*(pprimes + count++) = trial;	} while (count < max);	for(int i = 0; i < max; i++)	{		if(i % 5 == 0)			cout << endl;		cout << setw(10) << *(pprimes + i);	}	delete [] pprimes;	pprimes = 0;	cout << endl;	return(0);}