本文介绍了嗨,我不是要求代码只是对如何尝试以下问题的基本理解。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 编写一个程序,该程序使用for语句分别打印以下模式,一个在另一个之下。使用for循环生成模式。所有星号(*)都应该用cout<<<< '*';. [提示:最后两种模式要求每一行以适当数量的空格开头。] 我尝试了什么: 我没有尝试任何东西因为我不知道怎么做Write a program that uses for statements to print the following patterns separately, one below the other. Use for loops to generate the patterns. All asterisks (*) should be printed by a single statement of the form cout << '*';.[Hint: The last two patterns require that each line begin with an appropriate number of blanks.]What I have tried:I haven't tried anything since i don't know what do to推荐答案 nv3的解决方案是正确的,你需要一个外部循环来控制内部循环。一点代码 The solution of nv3 is correct, you need an outer loop, which controls the inner loops. A bit of codeint first = 10;for( int line = 0; line < 10; line++ ) { //inner loops for( int i = 0; i < first; i++ ) { cout << '*'; } // loop control at end first--;} 这篇关于嗨,我不是要求代码只是对如何尝试以下问题的基本理解。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-23 06:02