Skip to content

Instantly share code, notes, and snippets.

@iwagaki
Last active August 29, 2015 14:14
Show Gist options
  • Save iwagaki/add7a2c5c6e2d4811a65 to your computer and use it in GitHub Desktop.
Save iwagaki/add7a2c5c6e2d4811a65 to your computer and use it in GitHub Desktop.
Summarize odd numbers
#include <cstdio>
#include <cstdlib>
#include <string.h>
int summarize_odd_numbers(int a, int b)
{
int sum = 0;
for (int c = a; c <= b; c++)
{
if ((c & 0x1) == 1)
sum += c;
}
return sum;
}
int main() {
printf("sum = %d from %d to %d\n", summarize_odd_numbers(11, 20), 11, 20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment