// Solution to Project Euler Problem #28
// Sum of diagonals of spiral
#include <stdio.h>
#define DIMENSION 1001
main() {
int i, j;
int steps = (DIMENSION-1)/2; // number of layers
int sum = 1; // init with center of spiral
int currnum = 1;
for (i=1; i<=steps; i++) {
for (j=0; j<4; j++) {
currnum += 2*i;
sum += currnum;
}
}
printf("Solution: %d\n", sum);
}
Comments (0)
You don't have permission to comment on this page.