打印W形状的星号 [英] Print Asterisk in W shape

查看:108
本文介绍了打印W形状的星号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我想用W形打印星号。我似乎无法弄明白。一直在谷歌上寻找它。请帮忙。代码必须是C语言。 (我对编程比较陌生)



 * * 

* *

* * *

* * * *

* *







更新:(这里没有正确显示形状)



添加了代码块(它显示的是现在形状正确) - OriginalGriff [/ edit]

解决方案

使用标准函数printf编写非常简单

  int  printf( const   char  * format,...); 



将格式化数据打印到stdout

将格式指向的C字符串写入标准输出(stdout) 。如果format包含格式说明符(以%开头的子序列),格式化后的其他参数将被格式化并插入到结果字符串中,替换它们各自的说明符。

  #include   <   stdio。 h  >  

int main( )
{

printf( * * \ n);
printf( \ n);
printf( * * \ n);
printf( \ n);
printf( * * * \ n);
printf( \ n);
printf( * * * * \ n);
printf( \ n);
printf( * * \ n);

return 0 ;
}



问候,

Alex


因为它是C,你应该使用< pre lang =c ++> printf( theline \ n);

每一行。



所以,这应该是最终的样子:



  #include   <   stdio.h  >  
#include < conio.h >

int main(){
printf( * * \ n);
printf( * * \ n);
printf( * * * \ n);
printf( * * * * \ n);
printf( * * \ n);
getch(); // 如果您不使用某些输入功能,程序将退出而不让您看到验证
return 0 ;
}


Guys, I want to print asterisk in W shape. I can't seem to figure it out. Been looking for it all over Google as well. Need help, please. The code has to be in C language. (I'm relatively new to programming)

*         *

*         *

*    *    *

*  *   *  *

*         *




Update: (It's not displaying the shape correctly here)

[edit]Code block added (it's displaying the shape properly now) - OriginalGriff[/edit]

解决方案

It is very easy to write using standard function printf

int printf ( const char * format, ... );


Print formatted data to stdout
Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.

#include <stdio.h>

int main()
{

    printf("*         *\n");
    printf("           \n");
    printf("*         *\n");
    printf("           \n");
    printf("*    *    *\n");
    printf("           \n");
    printf("*  *   *  *\n");
    printf("           \n");
    printf("*         *\n");

    return 0;
}


Regards,
Alex


Since it's C, you should use

printf("theline\n");

for each line.

So, that's how it should finally look:

#include<stdio.h>
#include<conio.h>

int main(){
  printf("*       *\n");
  printf("*       *\n");
  printf("*   *   *\n");
  printf("* *   * *\n");
  printf("*       *\n");
  getch(); //if you don't use some input function, the program will exit without letting you see the tesult
  return 0;
}


这篇关于打印W形状的星号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆