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;

)

Recommended Answers

All 4 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.