Co-authored-by: sigonasr2 <sigonasr2@gmail.com>

This commit is contained in:
sigonasr2, Sig, Sigo 2022-07-14 18:05:09 +00:00 committed by GitHub
parent bbab1294fc
commit ebaee399f6
5 changed files with 48 additions and 18 deletions

BIN
archives/6/current Executable file

Binary file not shown.

26
archives/6/src/main.c Normal file

@ -0,0 +1,26 @@
#include <stdio.h>
#include "utils.h"
/*
The sum of the squares of the first ten natural numbers is,
The square of the sum of the first ten natural numbers is,
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is .
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
https://projecteuler.net/problem=6
*/
int main(int argc,char**argv) {
int sumOfSquares=0,squareOfSum=0;
for (int i=0;i<=100;i++) {
sumOfSquares+=i*i;
}
for (int i=0;i<=100;i++) {
squareOfSum+=i;
}
squareOfSum*=squareOfSum;
printf("%d - %d = %d",squareOfSum,sumOfSquares,squareOfSum-sumOfSquares);
return 0;
}

7
archives/6/src/utils.h Normal file

@ -0,0 +1,7 @@
#define true 1
#define false 0
#define boolean char
struct String{
int length;
char*str;
};

BIN
current

Binary file not shown.

@ -2,28 +2,25 @@
#include "utils.h"
/*
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
The sum of the squares of the first ten natural numbers is,
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
The square of the sum of the first ten natural numbers is,
https://projecteuler.net/problem=5
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is .
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
https://projecteuler.net/problem=6
*/
int main(int argc,char**argv) {
int numb=1;
while (true) {
boolean isDivisible=true;
for (int i=1;i<=20;i++) {
if (numb%i!=0) {
isDivisible=false;
break;
}
}
if (isDivisible) {
printf("%d is divisible!",numb);
break;
} else {
numb++;
int sumOfSquares=0,squareOfSum=0;
for (int i=0;i<=100;i++) {
sumOfSquares+=i*i;
}
for (int i=0;i<=100;i++) {
squareOfSum+=i;
}
squareOfSum*=squareOfSum;
printf("%d - %d = %d",squareOfSum,sumOfSquares,squareOfSum-sumOfSquares);
return 0;
}