当前位置: > 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):

提问时间: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的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.