Home > Back-end >  Input a number of natural Numbers, the last is 0 (end of said input), the output is greater than the
Input a number of natural Numbers, the last is 0 (end of said input), the output is greater than the

Time:09-16

#include
using namespace std;
Int main ()
{
Int a, b;
Float c;
int n;
For (a=0, b=0;; +, b +=n, c=1.0 *
b/a){
Cin> n;
If (n==0) break;
}
Cout<& lt;" The average="& lt; return 0;
}
This want how to just can make the output is the result of the "greater than the average number of"

CodePudding user response:

Using a container to the input values are stored, calculate the average, in comparing the

CodePudding user response:

Or an array input number

CodePudding user response:

Not very understand, can you help me to change

CodePudding user response:

For reference array version of
 
#include
using namespace std;
Const int N=1024;

Int main ()
{
Int arr [N].
Int I, a=0, b=0, count=0;
Float c;

for (i=0; I{
Cin & gt;> Arr [I];
B +=arr [I];

If (arr [I]==0)
{
A=I;
break;
}
}

C=b * 1.0/a;
for (i=0; I{
If (arr [I] & gt; C)
count++;
}

Cout<& lt;" The average="& lt; Cout & lt; <"Greater than the average number of:" & lt; return 0;
}

CodePudding user response:

reference 4 floor CHXCHXKKK response:
array for reference version of the
 
#include
using namespace std;
Const int N=1024;

Int main ()
{
Int arr [N].
Int I, a=0, b=0, count=0;
Float c;

for (i=0; I{
Cin & gt;> Arr [I];
B +=arr [I];

If (arr [I]==0)
{
A=I;
break;
}
}

C=b * 1.0/a;
for (i=0; I{
If (arr [I] & gt; C)
count++;
}

Cout<& lt;" The average="& lt; Cout & lt; <"Greater than the average number of:" & lt; return 0;
}

It is recommended to use the vector
 
#include
#include
#include
using namespace std;
Int main ()
{
vector a;
int n;
While (cin> N)
Amy polumbo ush_back (n);
Float the count;
The count=the accumulate (a.c the begin (), a.c end (), 0.0) * 1.0/a.s considering ();
Int num.
For (const auto& P: a)
If (p> The count)
+ + num.
Cout<& lt;" The mean: "& lt; Cout<& lt;" Is greater than the average number of: "& lt; return 0;
}
  • Related