Problem 10

// Project Euler - Problem 10
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int main (int argc, char *argv[]) {

	long i = 1;
	long j = 2;
	long topend = atoi(argv[1]);
	long long total = 2;

	while (i<topend) {
		while (j<i) {
			if (i % j != 0) {
				if (j == (i - 1)) {
					total = total + i;
				}
				j++;
			} else if (i % j == 0) {
				j = i;
			}
		}
		j=2;
		i++;
	}
	cout << total << "\n";
	return EXIT_SUCCESS;
}

Previous page: Problem 9
Next page: Problem 13