The following program is to produce the sum of Even and Odd array element. The program works properly when I use int instead of double. But getting errors when using double. Could anyone tell me what is the problem? Cus I wan it by using double array.
and I don't understand this step too >>
for (i = 0;i <= 10;i++)
{
a = i;
}
what does it mean? THANKS.
#include <stdio.h>
void sum(double a[], int n);
int main()
{
int i, n = 10;
double a[11];
for (i = 0;i <= 10;i++)
{
a[i] = i;
}
sum(a, n);
}
void sum(double a[], int n)
{
int i;
int esum = 0, osum = 0;
for (i = 0;i <= n;i++)
{
if (a[i] % 2 == 0)
esum = esum + a[i];
else
osum = osum + a[i];
}
printf("Sum of Even %d\n", esum);
printf("Sum of Odd %d\n", osum);
}