Last active
July 24, 2016 19:49
-
-
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
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
//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