//---------------------------------------------------------------------------------
// Functions: main()
//
// File: Prime.cpp
//
// Title: Prime Factorization
//
// Description: This file contains funtion main () which will calculate the
// prime factors of positive whole numbers.
//
// Programmer: Joanne Pietryga
//
// Date: 02/13/2008
//
// Version: 1.01
//
// Environment: Hardware:IBM Pentium+
// Software: Windows XP or 98+ with .NET framework for
// execution;
// Compiles under Microsoft Visual C++ 2003
//
// Input: int whole (the whole number in which to find the prime factors for)
//
// Output: prompts, display of prime factors to console
//
// Calls: primeFactor()
// Called By: n/a
// Parameters: void
//
// Returns: int EXIT_SUCCESS = successful
//
// History Log:
//
//
//
//------------------------------------------------------------------------------
#include <iostream>
#include <cstdlib>
#include <exception>
#include <cmath>
#include <cctype>
using namespace std;
void primeFactor(long wholeNumber);
int main(void)
{
int whole = 0;
char again = 'N';
do
{
system("cls");
do
{
cout << "Please enter a Whole number greater than 1: ";
cin >> whole;
cin.get();
if(whole < 1 || isalpha) // cannot be negative number not defined
cerr << "***Whole number cannot < 1!***" << endl;
}while(whole <1 || isalpha);
puts("Press the \"Enter\" key to continue");
cin.get(); // hold window open
return EXIT_SUCCESS;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void primeFactor(long wholeNumber)
{
int i=2;
static int count = 0;
if(wholeNumber!=2)
{
do
{
if(wholeNumber%i==0) // if it is divisible it is not prime
{
cout << "(" << i << ")";
count++;
primeFactor(wholeNumber/i);
return;
}
i++;
}
while(i <= sqrt((long double)wholeNumber));
}