I decided to make a small program that found prime numbers, and after an hour or so of tweaking i came up with something that was about 30 times faster than my first attempt, however I still have a couple of questions:
1. Is there an alternative to goto
2. How else can I optomise it further/any further improvements?
3. It only really needs to test if it is divisible by prime numbers, not every number, is there a way of doing this without taking up too much memory, and if so what shall i use, and will it even be quicker?
Thanks for any help:
Code:
Code:
#include <iostream>
using namespace std;
// varaiables
int num=0;
int i;
int j;
int main()
{
for (j=1; j <=9999; ++++j)
{
for (i=3; i <((j+1)/2); ++++i)
{
if (j%i==0) goto moo;
}
cout << j <<endl;
moo:;
}
cin >> num;
}