Saturday 14 March 2015

Program to find the sum of odd and even numbers Using C

# 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() ;
}


RUN 1 :
~~~~~~~
Enter the limit : 10
The odd numbers sum is : 25
The even numbers sum is : 30

No comments:

Post a Comment