mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-12 14:40:46 -05:00
20 lines
396 B
Zig
20 lines
396 B
Zig
|
pub fn squareOfSum(number: usize) usize {
|
||
|
var sum: usize = 0;
|
||
|
for (0..number + 1) |i| {
|
||
|
sum += i;
|
||
|
}
|
||
|
return sum * sum;
|
||
|
}
|
||
|
|
||
|
pub fn sumOfSquares(number: usize) usize {
|
||
|
var sum: usize = 0;
|
||
|
for (1..number + 1) |i| {
|
||
|
sum += i * i;
|
||
|
}
|
||
|
return sum;
|
||
|
}
|
||
|
|
||
|
pub fn differenceOfSquares(number: usize) usize {
|
||
|
return squareOfSum(number) - sumOfSquares(number);
|
||
|
}
|