View Single Post
Old 10-24-2011, 04:25 PM   #69
fido123
FFR Player
 
fido123's Avatar
 
Join Date: Sep 2005
Age: 32
Posts: 4,245
Default Re: THE project euler thread

Worked on this for a little bit one night. Did 1, 2, and 6 all in C:


Question 1:
Code:
#include <stdio.h>

int main() {
        int sum=0, x;
        for (x=1; x < 1000; x++) if (x % 3 == 0 || x % 5 == 0) sum += x;
        printf ("%d\n", sum);
}



Question 2:

Code:
#include <stdio.h>

int main() {
        int sum=0, x=0, y=1, z;
        do {
                z = x + y;
                x = y;
                y = z;
                if (y % 2 == 0) sum += y;
        } while (y < 4000000);
        printf ("%d\n", sum);
}



Question 6:

Code:
#include <stdio.h>
#include <math.h>

int main() {
        int x, sq=0, sum=0;
        for (x = 1; x <= 100; x++) {
                sq += pow (x, 2);
                sum += x;
        }
        sum = pow (sum, 2);
        x = sum - sq;
        printf ("%d\n", x);
}


Easy stuff so far but I'm not really all that knowledgeable about math at all so I'm not sure how far I'll get with this lol.

Last edited by fido123; 10-24-2011 at 04:28 PM..
fido123 is offline   Reply With Quote