|
Written by Gurito
|
|
This was a program we had to implement at the university a couple of months ago... It's just a tiny piece of code showing how to perform the sum of the squared numbers in [0, N]. That means, 1^2 + 2^2 + ... + N^2. It's written in c and, well.. you'll find it pretty straight forward.
/* This program calculates the sum of the squared numbers in * the interval [0,N] without doing any multiplication. * * You may use/change the code any way you want. * This program was made with academic purposes. * */ #include <stdio.h> int main (argsc, argsv) int argsc; char* argsv[]; { int N = 0; for(N=1; N<11; N++) { int x = 0, c = 0, d = 1, e = 3; while (x<N) { x = x + 1; c = c + d; d = d + e; e = e + 2; } printf("The sum of the squares is: %i\n",c); } return 0; }
|
|
Last Updated on Tuesday, 31 March 2009 15:13 |