| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 673 人关注过本帖
标题:【求助】一个带 continue 的 for 循环,如何等价改为 while 循环?
只看楼主 加入收藏
littledidi
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-10-17
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
【求助】一个带 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 ) ;
   }
}
搜索更多相关主题的帖子: continue reading average between include 
2014-10-17 13:49
hackrol
Rank: 4
来 自:世界和平组织
等 级:业余侠客
帖 子:62
专家分:267
注 册:2014-9-6
收藏
得分:10 
while(n!=-1)...
2014-10-17 23:04
中国好菜鸟
Rank: 2
等 级:论坛游民
帖 子:1
专家分:10
注 册:2014-10-14
收藏
得分:10 
大哥,在哪里发帖啊 ?我也想问问题
2014-10-18 07:34
快速回复:【求助】一个带 continue 的 for 循环,如何等价改为 while 循环?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011590 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved