Skip to content

Instantly share code, notes, and snippets.

@wohhie
Last active July 24, 2016 19:49
Show Gist options
  • Save wohhie/38c2ccd8d19439e0c161db611d2bea57 to your computer and use it in GitHub Desktop.
Save wohhie/38c2ccd8d19439e0c161db611d2bea57 to your computer and use it in GitHub Desktop.
C program to find the sum of odd and even numbers from 1 to N
//C program to find the sum of odd and even numbers from 1 to N
#include <stdio.h>
int main() {
int sum_odd = 0;
int sum_even = 0;
int num;
int i;
printf("Enter number number: ");
scanf("%d", &num);
for (int i = 0; i < num; i++) {
if (i % 2 == 0) {
sum_even = sum_even + i;
}
else {
sum_odd = sum_odd + i;
}
}
printf("\n");
printf("Summation of even: %d\n", sum_even);
printf("Summation of odd: %d\n", sum_odd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment