Write a C++ program that prompts for a number of rows from the user and then prints an hourglass of
题目
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):
答案
我没有完全看你的题目要求,看了输出的星号形状,我写了一个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的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
热门考点
- 下列哪种形态结构与小肠的吸收功能无关?
- bvbvvbvbvbvbvb 关于夏风的诗句
- 列举3个常见的机械运动的实例
- 当a=( )时,a-3的绝对值+1有最小值,最小值是( )
- 一个梯形的上底是下底的3倍,如果将下底延长6厘米,就成了一个平行四边形,这个梯形的上底和下底各()厘
- 相似三角形,(用两角相等的两个三角形相似证)
- 动物和人体内具有分裂和分化能力的细胞称为干细胞.对右图的相关叙述中,正确的是
- 一个正方形木块是125立方厘米,现在将它锯成8块同样大小的正方体小木块,求每个正方体小木块的表面积?
- 社戏,鲁迅的,问一个修辞
- 已知y=x^2-3,且y的算数平方根为4,求x的值