Home > Back-end >  Pray god help to look at the code where the error, thank you very much
Pray god help to look at the code where the error, thank you very much

Time:09-21

Beginners can not see where there is a problem, not an error, you can perform,
Would like to ask the average has been=0,
#include

Float business (float sum [10]);

Void main ()
{
Float score [10], the result;

Printf (" please enter the number 10: \ n ");

The scanf (" % d ", & amp; Score);

Result=average (score);

Printf (" business=% f ", result);



}
Float business (float sum [10])
{

Float resule=0, I;

for(i=0; i<10; I++)
{
Resule +=sum [10].

}
Resule/=10;

Return the resule;
}

CodePudding user response:

The building Lord did not make clear the scanf usage, if you want to input 10 value to use a loop to input, this will only get a value, the array a [] in the scanf don't add & amp;
Is address values, then the function part, resule +=sum [10]. This is not a 10, but, every time you add is an array of all 9, is zero. So you output is 0

CodePudding user response:

#include



Float business (float sum [10]);

Void main ()
{
Float score [10], the result;

Printf (" please enter the number 10: \ n ");

for (int i=0; I & lt; 10; I++)
{
The scanf (" % f ", & amp; Score [I]);
}

Result=average (score);

Printf (" business=% f ", result);



}
Float business (float sum [10])
{

Float resule=0;

for (int i=0; I & lt; 10; I++)
{
Resule +=sum [I];
}
Resule/=10;

Return the resule;
}

The building Lord help you to change good, not
the upstairs.

CodePudding user response:

Ok thank you very much,

CodePudding user response:

refer to the second floor flowers blowing in the wind flowers response:
# include & lt; Stdio. H>



Float business (float sum [10]);

Void main ()
{
Float score [10], the result;

Printf (" please enter the number 10: \ n ");

for (int i=0; I & lt; 10; I++)
{
The scanf (" % f ", & amp; Score [I]);
}

Result=average (score);

Printf (" business=% f ", result);



}
Float business (float sum [10])
{

Float resule=0;

for (int i=0; I & lt; 10; I++)
{
Resule +=sum [I];
}
Resule/=10;

Return the resule;
}

The building Lord help you to change good, don't believe the upstairs,

The upstairs also will be a problem

CodePudding user response:

 # include 


Float business (float sum [10], int len);

//void main ()
Int main ()
{
Float score [10], the result;
int i;

Printf (" please enter the number 10: \ n ");

For (I=0; I & lt; 10; I++)
//the scanf (" % d ", & amp; Score [I]);
The scanf (" % f ", & amp; Score [I]);

Result=average (score, 10);

Printf (" business=% f ", result);

return 0;
}
Float business (float sum [10], int len)
{

Float resule=0;
int i;

//for (I=0; i<10; I++)
for(i=0; i{
//resule +=sum [10].
Resule +=sum [I];

}
Resule/=len;

Return the resule;
}

For your reference ~

Still need to have a good learn ~ for array
  • Related