如何在c编码中完成这个模式 [英] how to done this patterm in c coding

查看:50
本文介绍了如何在c编码中完成这个模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0 1 2 3 4 5 6 7 8 9
. . . . . * . . . . 
. . . . . . . * . .
. . . . * . . . . .
. . * . . . . . . .





[edit]已添加代码块[/ edit]



[edit] Code block added[/edit]

推荐答案

我们无法用基于这些小信息的通用解决方案来解决这个问题:我们不知道您使用什么规则来生成模式。



所以唯一回答我们可以给你很简单:

We can't answer this with a generalised solution based on that little information: we have no idea what rules you are using to generate the pattern.

So the only answer we can give you is trivial:
printf("0 1 2 3 4 5 6 7 8 9\n");
printf(". . . . . * . . . .\n");
printf(". . . . . . . * . .\n");
printf(". . . . * . . . . .\n");
printf(". . * . . . . . . .\n");



如果你想要一个通用的逗留,那么你需要考虑管理模式生成的规则。


If you want a generalised sojourn, then you need to consider the rules that govern the generation of the pattern.


更好是一个更智能的解决方案。



我写了一些代码,我希望它有效,但它应该显示我的概念。

- for line for line output

- 用于打印星星的标志数组



better is a solution with some more intelligence.

I wrote some code, I hope it works, but it should show my concept.
- for Loop for line output
- flag array to print stars

for( int i = 0; i < 8; i++)
{
printf("0"+i);
}
printf("\n");

int stars[] = {5,7,4,2};

for(int l = 0; l < 4; l++)//outer loop
{
for(int i = 0; i < 8; i++)//inner loop
{
if( stars[l] == i ) ? printf("*") : printf(" ");
}
printf("\n");
}


这篇关于如何在c编码中完成这个模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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