Program to find the sum of odd and even numbers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i, osum = 0, esum = 0;
clrscr();
printf("Enter the limit : ");
scanf("%d", &n);
for(i = 1 ; i <= n ; i = i + 2)
osum = osum + i;
for(i = 2 ; i <= n ; i = i + 2)
esum = esum + i;
printf("\nThe odd numbers sum is : %d", osum);
printf("\n\nThe even numbers sum is : %d", esum);
getch();
}
Output:
Enter the limit : 10
The odd numbers sum is : 25
The even numbers sum is : 30
-
UpdatedDec 30, 2019
-
Views14,527
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order