Timeline for Calculating sum of squares in C
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 29, 2017 at 11:34 | comment | added | KjMag | The statement that there is no performance difference between the two approaches is premature. I understand that you've measured it once, and one measurement is not enough to determine it. Also, the difference may be negligible for small n, but I can imagine that in case of n being of the order of million, execution time will differ significantly. | |
Aug 28, 2017 at 17:49 | history | edited | Michał Paszkowski | CC BY-SA 3.0 |
Corrected solution
|
Aug 28, 2017 at 15:52 | comment | added | chux |
Theunsigned idea is good, yet too late. unsigned int numerator = (n * (n + 1)) * (2 * n + 1); assigns an int to an unsigned for no benefit. I'd recommend to use unsigned int sumSquares(unsigned int n) and drop the unneeded if (n <= 0) test.
|
|
Aug 27, 2017 at 16:38 | history | edited | Michał Paszkowski | CC BY-SA 3.0 |
Fixed grammar
|
Aug 27, 2017 at 16:22 | history | answered | Michał Paszkowski | CC BY-SA 3.0 |