25 August 2009

Prims list


//Create Prime list on a file
//Author: Ahmed Sayed
#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
  int num;
  cout << "Enter Range ";
  ofstream source;
  source.open("Prime List.txt");
cin >> num; 
 for (int x=1; x<num; x++)
{
  bool flag = true;
 
  for (int i = 2; i < x; i++)
  if (x%i==0)
    flag = false;
    
   if (flag)
  source << x << endl;
  }
  
system ("pause");
return 0;
}