当前位置 :
WriteaC++programthatpromptsforanumberofrowsfromtheuserandthenprintsanhourglassofthatnumberofrows.Yourhourglassmustabuttheleftmargin.Youmayuseonlythesinglecharacters''(space),'*'(asteriskorstar),andendlor
1人问答
更新时间:2024-04-26 20:37:13
问题描述:

WriteaC++programthatpromptsforanumberofrowsfromtheuserandthenprintsanhourglassofthatnumberofrows.

Yourhourglassmustabuttheleftmargin.Youmayuseonlythesinglecharacters''(space),'*'(asteriskorstar),andendlor'n'(newline)foryourhourglass.Youmaynotuseanyiomanipformattingcommandslikesetw()forthisprogram.

Yourhourglassmusthavebetween3and23rows,inclusive.Youmustforceareasonableinputfromtheuserfornumberofrows(donotlettheusergetpastthenumberofrowspromptunlesstheyenterareasonablevalue).Thenumberofrowsmustbeodd,soiftheuserentersanevennumber,addonetothenumberofrows.

YouMUSTusethealgorithmwediscussinclass.Particularly,youmustcalculatethenumberofspacesandstarsinthecurrentrowinoneplace,notspreadoutamongotherpartsofthecode.Donotjustfigureoutthenumberofspacesandstarsonthefirstrowbeforeprintingtherows,thenadjustthemupordownasyouprintrows.Workouthowtocalculatethesevaluesforeachrowgivenjustthecurrentrownumberandthetotalnumberofrows.Iwillgivehintsabouthowtodothisinclass.

Forexample,iftheuserenterseither6or7forthenumberofrows,printthefollowing:(50points):

金晓滨回答:
  我没有完全看你的题目要求,看了输出的星号形状,我写了一个C语言程序,你看看吧.#includeintmain(void){introw,i,j;//row是输入的行数scanf("%d",&row);if(row%2==0)//如果是偶数,则行数加一row+=1;for(i=row;i>=1;...
最新更新
PC端 | 移动端 | mip端
问答网(wenda2.com)汇总了汉语字典,新华字典,成语字典,组词,词语,在线查字典,中文字典,英汉字典,在线字典,康熙字典等等,是学生查询学习资料的好帮手,是老师教学的好助手。
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。

邮箱:联系方式:

Copyright©2009-2021 问答网 wenda2.com 版权所有 闽ICP备2022000227号-1