打印沙漏

#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;
}

posted @ 2018-09-07 17:28  云破月来花弄影  阅读(217)  评论(0编辑  收藏  举报