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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

PE028_c

Page history last edited by Kenneth Finnegan 15 years, 7 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.