Date created: 07/10/11 19:08:29. Last modified: 12/13/12 11:41:20

Problem 5

// Project Euler - Problem 5
#include <stdlib.h>

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

        int natural = atoi(argv[1]);
        int i = 1;
        int j = 1;

        while (1) {
                while(j<=natural) {
                        if (i % j == 0) {
                                if (j==natural) {
                                        printf("Its %d\n", i);
                                        exit(EXIT_SUCCESS);
                                }
                                j++;
                        } else {
                                j = natural + 1;
                        }
                }
                i++;
                j=1;
        }
        return EXIT_SUCCESS;
}

Previous page: Problem 4
Next page: Problem 6