calculate and display the average of all even values .

#include<stdio.h>

int main()
{

int numArrays[] = {2, 67, 23, 5, 7, 34, 14, 4, 8, 62};
int i, sum=0, ave=0;

for(i=1; i<10; i++)
{
if(numArray[i]%2==0)
printf("%d", numArray[a]);
total+=numArray[a];
sum=sum+total;

printf("the total of all even number is; %d", sum);
}
ave=(float)sum/n;
printf("the average of all even numbers is: %f", ave);

returtn 0;

)

Your program is missing { and } around the if statement because the if statement consists of multiple lines

if(numArray[i]%2==0)
{
    printf("%d", numArray[a]);
    total+=numArray[a];
}

Line 20 also has a problem: variable n was never declared, and the result will only be an integer because ave is an integer.

Edited 4 Years Ago by Ancient Dragon

calculate and display the average of all even values .

#include<stdio.h>

int main()
{

int numArrays[] = {2, 67, 23, 5, 7, 34, 14, 4, 8, 62};
int i, sum=0, 
double ave=0;

for(i=1; i<10; i++)
{
if(numArray[i]%2==0)
{
    printf("%d", numArray[a]);
    total+=numArray[a];
}
{
sum=sum+total;

printf("the total of all even number is; %d", sum);
}
ave=(float)sum/n;
printf("the average of all even numbers is: %f", ave);

returtn 0;
}

/* how about this one? */

If you have compiled this, clearly it won't compile. You need to report the errors. "returtn" is misspelled.

Why bother having a sum AND a total variable. Just use one. They mean the same thing.

When asking for help, EXPLAIN what problem you are having. Do not expect us to try to figure out what it does wrong -- tell us!

And put only the code in CODE Tags -- not the entire post.

This article has been dead for over six months. Start a new discussion instead.