# HG changeset patch # User chrish # Date 1333658842 14400 # Node ID db887b054a3499dd0e50103eca9cf2f1694aa858 # Parent 0721213b6445f66657247c880e9748acf5acfd28 adding problems 5,6 & 9 diff --git a/problem0005/5.py b/problem0005/5.py new file mode 100644 --- /dev/null +++ b/problem0005/5.py @@ -0,0 +1,16 @@ +# Since the smallest number for being divisible is 2520 +# is stands to reason 1-20 must be larger +x = 2510 +IsDivisibleFrom1To20 = False +while not IsDivisibleFrom1To20: + # In order by be evenly divible by 10 it must be a factor of 10 + x = x + 10 + + # Go through the numbers. + # Everything is divible by 1, and we know it is even so 2 works too + for y in range(3,20): + if x % y != 0: + break + else: + IsDivisibleFrom1To20 = True +print x diff --git a/problem0006/6.c b/problem0006/6.c new file mode 100644 --- /dev/null +++ b/problem0006/6.c @@ -0,0 +1,39 @@ +#include +#define TRUE 1 +#define FALSE 0 +long AddSquares(int limit); +long SquareSum(int limit); +int main() +{ + int limit = 100; + long sumOfSquares; + long squareOfSum; + sumOfSquares = AddSquares(limit); + squareOfSum = SquareSum(limit); + printf("Sum Of Squares: %ld\n", sumOfSquares); + printf("Square Of Sum: %ld\n", squareOfSum); + printf("Difference: %ld\n", squareOfSum-sumOfSquares); + + return 0; +} + +long AddSquares(int limit) +{ + int x; + long sum = 0; + for (x=1;x<=limit;x++) + sum += (x*x); + + return sum; +} + +long SquareSum(int limit) +{ + + int x; + long sum = 0; + for (x=1;x<=limit;x++) + sum += x; + + return sum*sum; +} diff --git a/problem0009/9.c b/problem0009/9.c new file mode 100644 --- /dev/null +++ b/problem0009/9.c @@ -0,0 +1,23 @@ +#include +#include + +int main() +{ + int a,b; + int c1,c2; + + for (a=1;a<1000;a++) + { + for (b=1;b<1000;b++) + { + c1 = sqrt((a*a) + (b*b)); + c2 = 1000 - (a + b); + if (c1 == c2 && (c1*c1) == a*a + b*b) + goto end; + } + } +end: + printf("a = %d;b = %d;c = %d\n", a, b, c1); + printf("abc = %d\n\n", a*b*c1); + return 0; +}