The C program calculates the sum of odd numbers
and sum of even numbers from 1 to N.
It first separates the odd and even numbers from 1
to N, and then adds all odd and even numbers separately. The program can be
successfully compiled and run on any system:
#include <stdio.h>
int main() {
int i, N, oddSum = 0, evenSum = 0;
printf("Enter the value of N: ");
scanf ("%d", &N);
if (i % 2 == 0)
evenSum = evenSum + i;
else
oddSum = oddSum + i;
}
}
printf ("\nSum Of Odd Numbers from 1 to N =
%d\n", oddSum);
printf ("\nSum Of Even Numbers from 1 to N =
%d\n", evenSum);
}