首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

只想出了两种,还有一种是啥?解决方案

2012-03-19 
只想出了两种,还有一种是啥?C/C++ code#include stdio.hint main(){int iint n 20for( i 0 i n

只想出了两种,还有一种是啥?

C/C++ code
#include <stdio.h>int main(){    int i;    int n = 20;    for( i = 0; i < n; i-- )        printf("-");    return 0;}

这段代码原意是打印20次“-”符号,但是现在会陷入死循环,有三个方式只修改一个字符可实现。只想出了两种:
C/C++ code
#include <stdio.h>int main(){    int i;    int n = 20;    for( i = 0; -i < n; i-- )        printf("-");    return 0;}

C/C++ code
#include <stdio.h>int main(){    int i;    int n = 20;    for( i = 0; i < n; n-- )        printf("-");    return 0;}


还有一种想不出来是什么了。


[解决办法]
C/C++ code
#include <stdio.h>int main(){    int i;    int n = 20;    for( i = 0; i + n; i-- )        printf("-");    return 0;} 

热点排行