Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

C语言算法题-开灯问题 代码有点看不懂求大神指点?

clipboard.png

clipboard.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

同学你圈的这段代码就是把结果输出的语句。意思也就是第一个输出的数字前不加空格,后面的每个数字与上一个数字加上一个空格。
first就是一个标志位,首先赋值为1,在循环输出的时候判断,此时first=1,是第一个结果输出,那么直接将结果打印,并将first设置为0,在打印后续输出的时候,此时的first=0(不是第一个数字了),那么先输出一个空格然后再打印数字。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...