thanks laserlight,probably good if you code that way if its on purpose
ok I post my messy looking code so far,with working code with buffer3 and with not working is buffer and buffer2,
first need to figure out to make it work,try floats later
Code:
#include "pch.h"
#include <iostream>
using namespace std;
int maxram;
int *buffer;
int *buffer2;
int buffer3[1024*1048];
float a, b, c, d, e, f, g, h;
float r, r2, r3, r4;
int i, j, k, l,composite;
int main()
{
maxram = 0x2000000000;
buffer=(int*)malloc(maxram);
memset(buffer, -1, maxram);
cout << "Primes and composites !\n";
for (i = 0; i < 1024000; i++) { buffer3[i] = 0;
}
for (i = 2; i < 1023;i=i+1 ) {
for (j = 2; j < 1023; j=j+1) {
composite = i * j;
buffer2 = buffer + composite;
buffer3[composite] = composite;
//*buffer2 = composite;
}
}
cout << "composites and primes:";
for (k = 2; k < 121; k=k+1) {
i = buffer3[k];
j = k;
if (i == 0) {
cout << " prime " << j << "\n";
}
else cout << "composite " << i << "\n";
}
free(buffer);
system("PAUSE");
}
121 in the last loop is on purpose temporary easier to check smaller printout
I have tried with optimizations in i,j forloop to step thru all odd numbers,but that breaks code so it prints lots of nonprimes as primes