• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.



Page history last edited by Kenneth Finnegan 12 years, 3 months ago

// 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.