Home>

### c - i'm sorry for a similar question program of average value using while statement

In a program that uses a while statement to find a value below the average value, I want to take the average of the values ​​up to that point when a value below 0 is entered. How should I set it up? (Does not include 0 or less)
I have no idea, so I would appreciate it if you could tell me.
For the time being, when I thought about it as a trial, it became as follows.
To be honest, I think that what i am doing is completely different, but please point out that as well.
* I don't know how to use the while statement and break.

include define NUM 10000

int main (void)
{
int Num = 0;
double test [NUM];
double dnumSum = 0;
double dnumAve = 0;
int i = 1;
int j;

printf ("Enter the number of data. \ N");
scanf ("% d",&Num);

while (Num<= 0)
{
printf ("There is an error in the input. Please enter it again. \ N");
scanf ("% d",&Num);
}

while (test [i]<0) {

printf ("Enter the value of the data. \ N");
scanf ("% lf",&test [i]);
i ++;
break;

dnumSum + = test [i];

}

dnumAve = (double) dnumSum/Num;

for (j = 0;j if (test [j]<= dnumAve) {
printf ("Data below the mean is% f. \ N", test [j]);

}
}

return 0;
}

• Answer # 1

How to use while (expression) {} ,,
->Repeat inside {} and execute while the expression is true.

while (test [i]<0) {

`test [i]`While it is true, it is executed, but since the value of the first test [i] is not set, it is unknown whether it is the result. Maybe,`Num`I just want to repeat it
->```while (iIs not it. In addition, it should be notediShould the default setting of be 0? (It's 1)```

``` Since the input is less than 0, would break look like this? if (test [i]<= 0) break;(i ++Will be after this) Also, to find the average dnumAve = (double) dnumSum/Num; Is invalid if the input is 0 or less, dnumAve = (double) dnumSum/i;Is not it? I just noticed it. However, this doesn't take into account the case where the first input is less than or equal to 0, but for now. (adsbygoogle = window.adsbygoogle || []).push({}); ```
``` ```
• ``` ```
``` ```
``` ```
``` Related articlesc - program to find the average valuec language program to display average weightc - program that waits for the input of two real numbers, then outputs the average, waits for the input of the third real numberprogram for calculating average temperature c languagewhy is there a compile error in the program that finds the average of the three numbers entered?c - different results are output in the program that gets the address of the variablequestion in c language standard (jis x3010:2003)c - program that uses global variablesi have a question about declaring a pointer in ci want to implement a special sort program that sorts by the sum of each digitc language: hashed program hangs during executionc - program that outputs the maximum value from the fourcomplete the program using printf statement only oncec - i want to make a program that finds x,y satisfying sum=x+y,prod=x*yon the deficiency of the program that approximates the base e of the natural logarithmc - how to write a program that finds a set of i,j,k that satisfies i^n+j^n+k^n=n (-10<=i,j,k<=10)i want to compile a c language program successfullyi want to be able to input the integer value n of this program by command argumentthe length of the mp3 obtained by the program does not match the value of the property of the file ```
``` ```
``` Related questions Why the cycle does not work with the Fread to process the binary file.?scanf () does not workabout how to store a c language txt file in an arrayabout how to store a c language txt file in an arraystring exchange using c language pointersc - sometimes heapsort does not sort wellcount the number of types of c language array elementsc - the while statement is not applied and ends without loopingthe output result does not match the value assigned to the c language 2d array (adsbygoogle = window.adsbygoogle || []).push({}); ```
``` ```
``` (function() { if((".artleft pre").length > 0){ \$(".artleft pre").addClass('prettyprint linenums'); prettyPrint(); }; \$(".artleft p > code").each(function() { if (\$(this).text().length >= 30) { \$(this).addClass('linecode'); }else{} }); })(); ```
``` ```
``` © 2019 Programming tutorial for beginners ```