码迷,mamicode.com
首页 > 其他好文 > 详细

Sony笔试题 ——完成打印图案的程序

时间:2014-06-25 14:49:07      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   http   com   width   

Sony笔试题 

完成下列打印图案的程序:

  * 

  *.*. 

  *..*..*.. 

  *...*...*...*... 

  *....*....*....*....*.... 

  *.....*.....*.....*.....*.....*..... 

  *......*......*......*......*......*......*...... 

  *.......*.......*.......*.......*.......*.......*.......*....... 

Technorati 标签:

 

  #include <stdio.h>  

  #define N 8  

  int main()  

  { 

   int i; 

   int j; 

   int k; 

   --------------------------------------------------------- 

   | | 

   | | 

   | | 

   --------------------------------------------------------- 

   return 0; 

  }

 

解题思路:

首先,通过最外层循环i=[0,N-1]输出从上到下的N’*’。

#define N 8

for(int i=0;i<N;i++)

{

putchar(‘*‘);

cout<<endl;

}

输出结果:

bubuko.com,布布扣 

再次,通过i的里层嵌套,打印出三角星。

#define N 8

for(int i=0;i<N;i++)

{

for(int j=0;j<=i;j++ )

{

putchar(‘*‘);

}

cout<<endl;

}

结果:

bubuko.com,布布扣

最后,通过k第三层循环打印’.’

for(int i=0;i<N;i++)

{

for(int j=0;j<=i;j++ )

{

putchar(‘*‘);

for(int k=0;k<i;k++)

{

putchar(‘.‘);

}

}

cout<<endl;

}

结果:

bubuko.com,布布扣

Sony笔试题 ——完成打印图案的程序,布布扣,bubuko.com

Sony笔试题 ——完成打印图案的程序

标签:style   class   blog   http   com   width   

原文地址:http://www.cnblogs.com/zjb0823/p/3806501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!