0
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;

)
4
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by WaltP
1

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 by Ancient Dragon

0
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? */
0

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.

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.