25 August 2009

prime numbers

// prime numbers 
/* This is a new method to calculate the prime numbers. Get odd numbers set,
   then subtract from it the set formed from multiplying odd numbers with each other.*/   
#include <iostream>
#include <fstream>
using namespace std;

int main()
{   int a, b, c, i; 
    int array[1000];
    i = 0;
    ofstream source;
    source.open("Prime Numbers.txt"); 
    source << "This is a list of all odd numbers where nonprimes numbers are hidden and replaced by -1." << endl; 
    source << "This gives us and leave us with the Prime Numbers shown below." << endl;
    source << endl << 2 << endl << 5 << endl;
    
    for (c=1; c<2000; c+=2)
        if (c%5==0)
            {array[i] = 0;i++;}
        else
            {array[i] = c;i++;}
            
    for (a=3; a<1000; a+=2)
        for (b=a; b<1000; b+=2)
            for (i=0; i<1000; i++)
                if ( a*b == array[i])
                     array[i] = -1;
    
    for (i=0; i<1000; i++)
        if (i%5==0)
            source << endl << "........\n" << array[i] << endl;   
        else
            source << array[i] << endl;                                   
        
    system("PAUSE");
    return 0;
    }