【求助】一个带 continue 的 for 循环,如何等价改为 while 循环?
新手学习中,作业遇到这一题,有continue,不太懂怎么把它完整转换为同样运算结果的while循环,感谢!/* ---------------------------------------------------------------- */
/* This program computes average of a few numbers between 0 and 100 */
/* The program will keep reading in numbers until -1 is inpu */
#include <stdio.h>
int main()
{
double n, total ; /* a number is input into n and add to total */
double average ; /* average of compute by total divide by i */
int i ;
total = 0 ;
printf( "\nCompute the average of some numbers between 0 and 100 \n" );
for( i = 0 ; ; i++ )
{ printf( "please input a number (-1 to stop input) :> ") ;
scanf( "%lg", &n ) ;
if ( n > 100 )
{ printf("Value input is too large. It is ignore!\n");
i-- ;
continue;
}
if ( n < -1 )
{ printf("Value input is too small. It is ignore!\n");
i-- ;
continue;
}
if ( n == -1 ) break ;
total = total + n ;
}
if ( i == 0 )
{ printf("No number is input! Nothing to compute the average!\n");
}
else
{ average = total / i ;
printf( " The average of all the numbers are : %g\n\n" , average ) ;
}
}