/* SUM OF EVEN AND ODD NUMBERS IN GIVEN ARRAY */
#include<stdio.h>
#include<conio.h>
main()
{
int i,n,a[10],esum=0,osum=0;
clrscr();
printf("\n Enter n value:");
scanf("%d",&n);
printf("\n Enter the array elements:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
esum=esum+a[i];
}
else
{
osum=osum+a[i];
}
}
printf("\n The sum of even array is:%d",esum);
printf("\n The sum of odd array is: %d",osum);
getch();
}
No comments:
Post a Comment