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的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
- 当物体下落时,其加速度为0.8g,若空气阻力不变,则将物体竖直上抛时到达最高点和正在最高点的加速度,急
- 青色是绿色还是蓝色?
- 高是10厘米的直角梯形,上底是下底的1.2倍,如果上底缩短3厘米,就构成一个长方形,求此梯形的面积.
- 用天平称得一堆钢珠为350g,取出其中20粒,称的质量为2.4g,问这堆钢珠共有多少粒?
- Na 、Mg,这样一个元素符号,左上、右上、左下、右下的数字各表示什么意思?
- lingo 程序
- 人教版八年级下册第6课《雪》的研讨与练习答案!
- 因式分解ab(c^2-d^2)-cd(a^2-b^2)
- 不管风吹浪打,胜似闲庭信步,今日得宽馀.
- We need to do morning exercises every day to keep in good __6__.
热门考点