首页 > 其他 > 详细

打印沙漏

时间:2018-09-07 17:44:56      阅读:127      评论:0      收藏:0      [点我收藏+]

#include<iostream>
using namespace std;
int main(){
 
 int number,temp=7,a=3;
 char c;
 cout<<"请输入沙漏数"<<endl;
 cin>>number;
 cin>>c;
 do{
  if(number<(temp+2*(a+2)))
   break;
  else if(number==(temp+2*(a+2))){
   temp=temp+2*(a+2);
   a=a+2;
   break;
  }
  else{
  temp=temp+2*(a+2);
   a=a+2;
  }
 }while(1);
 int t=(a+1)/2;
 for(int i=t;i>1;i--){
  for(int k=t-i;k>0;k--)
  {cout<<" ";}
   for(int j=1;j<=2*i-1;j++)
   {cout<<c;}
   cout<<endl;
 }
  for(int i=1;i<=t;i++){
  for(int k=t-i;k>0;k--)
  {cout<<" ";}
   for(int j=1;j<=2*i-1;j++)
   {cout<<c;}
   cout<<endl;
 }
  int h=number-temp;
  cout<<h<<endl;
   
  return 0;
}

打印沙漏

原文:https://www.cnblogs.com/zzstdruan1707-4/p/9606097.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!