题目
Write a C++ program that prompts for a number of rows from the user and then prints an hourglass of that number of rows.
Your hourglass must abut the left margin. You may use only the single characters ' ' (space), '*' (asterisk or star), and endl or '\n' (newline) for your hourglass. You may not use any iomanip formatting commands like setw() for this program.
Your hourglass must have between 3 and 23 rows, inclusive. You must force a reasonable input from the user for number of rows (do not let the user get past the number of rows prompt unless they enter a reasonable value). The number of rows must be odd, so if the user enters an even number, add one to the number of rows.
You MUST use the algorithm we discuss in class. Particularly, you must calculate the number of spaces and stars in the current row in one place, not spread out among other parts of the code. Do not just figure out the number of spaces and stars on the first row before printing the rows, then adjust them up or down as you print rows. Work out how to calculate these values for each row given just the current row number and the total number of rows. I will give hints about how to do this in class.
For example, if the user enters either 6 or 7 for the number of rows, print the following: (50 points):
Your hourglass must abut the left margin. You may use only the single characters ' ' (space), '*' (asterisk or star), and endl or '\n' (newline) for your hourglass. You may not use any iomanip formatting commands like setw() for this program.
Your hourglass must have between 3 and 23 rows, inclusive. You must force a reasonable input from the user for number of rows (do not let the user get past the number of rows prompt unless they enter a reasonable value). The number of rows must be odd, so if the user enters an even number, add one to the number of rows.
You MUST use the algorithm we discuss in class. Particularly, you must calculate the number of spaces and stars in the current row in one place, not spread out among other parts of the code. Do not just figure out the number of spaces and stars on the first row before printing the rows, then adjust them up or down as you print rows. Work out how to calculate these values for each row given just the current row number and the total number of rows. I will give hints about how to do this in class.
For example, if the user enters either 6 or 7 for the number of rows, print the following: (50 points):
提问时间:2021-02-28
答案
我没有完全看你的题目要求,看了输出的星号形状,我写了一个C语言程序,你看看吧.#include int main(void){int row,i,j;//row是输入的行数scanf("%d",&row);if(row%2==0)//如果是偶数,则行数加一row+=1;for(i=row;i>=1;...
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1as you will already know 有没有这样的说法?
- 2数子右上角的1/2是什么意思
- 3求证A(a,b),B(b,a),关于直线y=x对称
- 4regular structure是什么意思
- 5一又二分之一乘七分之五减括号负二又二分之一括号乘七分之五�
- 6人有笨和聪明之分吗?是不是聪明的人学东西就很快,如果我很笨怎么办?
- 7DER genuine 都有什么意思
- 8下图是某种零件的包装示意图,每个圆柱形零件的横截面的直径是1.2厘米.包装完成后,盒内空隙部分的体积是多少?(得数保留一位小数)
- 9若函数=1/lg(x²+bx+2b)的定义域为R,则b的取值范围为?
- 10已知x+y-2根号下x-4根号下y+5=0,求实数x,y的值
热门考点
- 124.When Jane ________goodbye to her Chinese friends,she could hardly hold back her tears.
- 2用括号内所给动词的正确时态填空
- 3“人群中钻出来一个大光头”运用了什么修辞手法?
- 4Is that your______?A.a picture.B.picture.
- 5如图所示,滑轮下挂重500N的物体G,滑轮重40N,绳和杠杆都是轻质的.要在图示位置使杠杆平衡,在杠杆的A点所加的竖直向上的力F应是(杠杆上标度的间距相等)( ) A.270N B.360N C.5
- 6There are a lot of people near the ________(enter) to the museum.
- 7learn to smile to yourself
- 8What is even more is that you will continue to try you best to do everything
- 9在“研究平抛物体运动”的试验中,可以测出小球经过曲线上任意位置的瞬时速度.实验简要步骤如下!1让小球
- 10直线xcosA+ycosA+c=0和直线 xsinA-ycosA+b=0的位置关系