Statement of C Program: This Program computes the Sum of Even and Odd Numbers stored in an Array of N integers:
#include<stdio.h>
#include<conio.h>
void main()
{
int num[20];
int i , esum , osum , N;
/* esum stands for Sum of Even Numbers and osum stands for Sum of Odd Numbers */
clrscr();esum = 0;
osum = 0;
printf("Enter the size of Array\n");
scanf("%d" , &N);
printf(" Enter Array elements\n");
for(i=0 ; i<N ; i++)
{
scanf("%d" , &num[i]);
}
for(i=0 ; i<N ; i++)
{
if((num[i] %2) ==0)
{
esum+ = num[i];
}
else
{
osum+ = num[i];
}
} /* End of for */
printf(" Sum of even Numbers = %d\n" , esum);
printf(" Sum of odd Numbers = %d\n" , osum);
} /* End of main() */
Output:
Enter the size of Array
5
Enter the Array elements
55
21
36
10
14
Sum of even Numbers = 60
Sum of odd Numbers = 76
36
10
14
Sum of even Numbers = 60
Sum of odd Numbers = 76
That's All
0 Response to "WAP to Calculate the Sum of Even and Odd Numbers Stored in an Array"
Post a Comment