Last active
August 29, 2015 14:14
-
-
Save iwagaki/add7a2c5c6e2d4811a65 to your computer and use it in GitHub Desktop.
Summarize odd numbers
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
#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