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
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 09:15:13
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
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):
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
我没有完全看你的题目要求,看了输出的星号形状,我写了一个C语言程序,你看看吧.
#include
int main(void)
{
int row,i,j;//row是输入的行数
scanf("%d",&row);
if(row%2==0)//如果是偶数,则行数加一
row+=1;
for(i=row;i>=1;i=i-2)//输出上面的倒三角形状的星号
{
for(j=0;j