Created
May 20, 2020 14:46
-
-
Save organic-nailer/ffb4dc13d8563d3602e5aaca9bfe3aa1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
print(sum1(100)); | |
print(sum2(100, start: 51)); | |
print(sum3(100, start: 21, step: 3)); | |
} | |
int sum1(int value) { | |
int result = 0; | |
for(int i=1; i <= value; i++) { | |
result += i; | |
} | |
return result; | |
} | |
int sum2(int value, {int start = 1}) { | |
int result = 0; | |
for(int i = start; i <= value; i++) { | |
result += i; | |
} | |
return result; | |
} | |
int sum3(int value, {int start = 1, int step = 1}) { | |
int result = 0; | |
for(int i = start; i <= value; i += step) { | |
result += i; | |
} | |
return result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment