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

main
sigonasr2, Sig, Sigo 3 years ago committed by GitHub
parent bbab1294fc
commit ebaee399f6
  1. BIN
      archives/6/current
  2. 26
      archives/6/src/main.c
  3. 7
      archives/6/src/utils.h
  4. BIN
      current
  5. 33
      src/main.c

Binary file not shown.

@ -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;
}

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

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;
}
Loading…
Cancel
Save