# Commits

committed 3c3f48d

Problem 7 & 10

• Participants
• Parent commits d3cfc69

` *~`
` *.exe`
` *.obj`
`+*.out`

# File problem0007/7.c

`+#include<stdio.h>`
`+#define TRUE 1`
`+#define FALSE 0`
`+#define NUMPRIMES 10001`
`+int IsPrime(int x);`
`+int main()`
`+{`
`+	long primes[NUMPRIMES];`
`+    int numPrimes;`
`+    int x;`
`+    numPrimes = ComputePrimes(primes, NUMPRIMES);`
`+ `
`+    printf("Found %d primes. \n\n", numPrimes);`
`+    for (x=0;x<numPrimes;x++)`
`+    {`
`+        char whitespace = (x+1) % 10 == 0 ? '\n' : '\t';           `
`+        printf("%3d%c", primes[x],whitespace);`
`+    }`
`+    printf("\n");`
`+    return 0;`
`+}`
`+ `
`+// Computes primes and returns how many primes it calculated`
`+int ComputePrimes(long primes[], int length)`
`+{`
`+    int numPrimes = 1;`
`+    int x;`
`+    long* arr = primes;`
`+ `
`+    // First prime`
`+    *arr = 2;`
`+    arr++;`
`+    for (x=3;numPrimes<length;x+=2)`
`+    {`
`+        if (IsPrime(x))`
`+        {`
`+            *arr = x;`
`+            arr++;`
`+            numPrimes++;`
`+        }`
`+    }`
`+    return numPrimes;`
`+}`
`+`
`+int IsPrime(long x)`
`+{`
`+    long y;`
`+    for (y=2;y<x;y++)`
`+        if (x % y == 0)`
`+            return FALSE;`
`+`
`+    return TRUE;`
`+}`

# File problem0010/10.c

`+#include<stdio.h>`
`+#define TRUE 1`
`+#define FALSE 0`
`+int IsPrime(long x);`
`+unsigned long long AddPrimes(int max);`
`+int main()`
`+{`
`+ `
`+    printf("\n\n%llu", AddPrimes(2000000));`
`+    printf("\n");`
`+    return 0;`
`+}`
`+ `
`+unsigned long long AddPrimes(int max)`
`+{`
`+    unsigned long long sum = 0;`
`+    int numPrimes = 0;`
`+    unsigned long x = 2;`
`+    int step = 1;`
`+ `
`+`
`+    for (x=2;x<max;x+=step)`
`+    {`
`+        // once we hit 3 we can start step 2`
`+        if (x == 3)`
`+            step = 2;`
`+        if (IsPrime(x))`
`+        {`
`+            sum += x;`
`+            numPrimes++;`
`+            printf("%10lu ~ %15llu\r", x, sum);`
`+            fflush(stdout);`
`+        }`
`+    }`
`+    return sum;`
`+}`
`+`
`+int IsPrime(long x)`
`+{`
`+    long y;`
`+    for (y=2;y<x;y++)`
`+        if (x % y == 0)`
`+            return FALSE;`
`+`
`+    return TRUE;`
`+}`