Created
May 3, 2023 17:09
-
-
Save sbatial/6f0ff11f77fb570708eefe82d05fb28c to your computer and use it in GitHub Desktop.
Summiert alle ungeraden Zahlen zwischen 1 und einem anzugebenden Wert.
This file contains hidden or 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
int sum_unger(int startwert) { | |
int sum = 0; | |
if (startwert < 1) { | |
return -1; | |
} | |
startwert += (startwert % 2) - 1; | |
while (startwert >= 1) { | |
sum += startwert; | |
startwert -= 2; | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment