Skip to content

Instantly share code, notes, and snippets.

@sbatial
Created May 3, 2023 17:09
Show Gist options
  • Save sbatial/6f0ff11f77fb570708eefe82d05fb28c to your computer and use it in GitHub Desktop.
Save sbatial/6f0ff11f77fb570708eefe82d05fb28c to your computer and use it in GitHub Desktop.
Summiert alle ungeraden Zahlen zwischen 1 und einem anzugebenden Wert.
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