现在的位置: 首页 > 综合 > 正文

sony面试题(输出* .这样的字符)

2012年08月31日 ⁄ 综合 ⁄ 共 294字 ⁄ 字号 评论关闭

输出如图所示的图像的程序如下:(这是一道sony的面试题)

#include<iostream>
using namespace std;
void dian(int n)
{
 while(n--)
 {
  cout<<".";
 }
}
void xing()
{
 cout<<"*";
}

int main()
{
 cout<<"输入你需要输出的行数:"<<endl;
 int line;
 cin>>line;
 for(int i=1;i<=line;i++)
 {
  int j=i;
 
  while(j--)
  {
   xing();
    dian(i-1);
   
  }
  cout<<endl;
 }
 return 0;
}

抱歉!评论已关闭.