使用c或C ++的星形图案 [英] star pattern using c or C++

查看:52
本文介绍了使用c或C ++的星形图案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c或C ++获得以下模式





How i can get the following pattern using c or C++


*     *
**   **
* * * *
*  *  *
* * * *
**   **
*     *





这里的用户输入是行数,两端都应该有对角线。请帮帮我。



here the user input is the no of rows and there should be diagonals from both ends. Please help me.

推荐答案

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



话虽如此,它并不复杂 - 但我不会给你任何代码!



1)分配一个大到足以容纳整行的字符数组(包括终止空值)

2)设置一个行数的循环,( for 循环没问题,变量为curRow)

3)在循环中,清除所有空格的行。

4 )然后,将第一个和最后一个字符设置为'*'

5)然后,将当前行号处的字符设置为'*',将字符设置为行数 - (当前行+ 1)到'*'

6)将行数中的字符设置为空'\ 0'

7)写行

8重复下一行循环。



轻松!总计:大约7行代码!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

Having said that, it's not complex - but I'll give you no code!

1) Allocate a character array big enough to hold the whole line (including a terminating null)
2) Set up a loop for the number of rows, (a for loop is fine, with a variable of curRow)
3) In the loop, clear the line to all spaces.
4) Then, set the first and last character to a '*'
5) Then, set the character at the current row number to a '*', and the character at the number of rows - (the current row + 1) to a '*'
6) Set the character at the number of rows to a null '\0'
7) Write the line
8 Repeat the loop for the next row.

Easy! Total: about 7 lines of code!


这篇关于使用c或C ++的星形图案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆