Top.Mail.Ru
The C++ Community's Journal -- Day
? ?
The C++ Community's Journal -- Day [entries|friends|calendar]
The C++ Community

[ userinfo | livejournal userinfo ]
[ calendar | livejournal calendar ]

My Prime Tester (In C++) [10 Jan 2007|09:01pm]
[ mood | Image amused ]

Here's a program that's supposed to tell whether a given number is prime. I want to get this out to lots of people, useless as the idea may sound. By the way, I'm sorta new to C++, so if this program's sorta... basic-looking to you, remember that I'm new.



#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int Number, int Potfact, int Reply)
{cout << "WARNING!" << endl;
cout << "PROGRAM ONLY WORKS FOR POSITIVE ODD NUMBERS LESS THAN 2^31." << endl;
system("PAUSE");
Input:
cout << "Input number for testing" << endl;
cin >> Number;
Potfact = 3;

while((Number / Potfact) >= Potfact)
{if((Number % Potfact) == 0)
{goto no;
}
else
{Potfact = 2 + Potfact;
}}
goto yes;

yes:
cout << "YES" << endl;
goto PAUSE;

no:
cout << "NO" << endl;
goto PAUSE;

PAUSE:
cout << "PRESS:" << endl;
cout << "1 to continue or" << endl;
cout << "2 to quit" << endl;
cin >> Reply;
if(Reply == 1)
{goto Input;
}
else
{return 0;
}}



P.S. I also have a copy of this program in the language I used when I created it: TI-BASIC. Visit my journal to read it, if you're interested.

18 comments|post comment

navigation
[ viewing | January 10th, 2007 ]
[ go | previous day|next day ]
Image