如何获得这样的输出? [英] How to get a output like this?

查看:74
本文介绍了如何获得这样的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<$> *
* *

* * *

* * * *

* * *

* *

*



我的尝试:



我试过for循环。但无法获得预期的输出。

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

void main()
{
int i,j;
scanf( %d,& j);
for (i = 0 ; i< = j; i ++)
printf ( *);
for (i = j; i< = 0 ; i--)
printf( *);
}

解决方案

Quote:

我试过for循环。但无法获得预期的输出。

更加努力。



尝试两个嵌套循环(行的外部循环,列的内部循环)。





[update]

您的代码没有使用嵌套循环。

也没有使用换行符。

上半年模式的食谱:



假设 r 正在遍历行。

假设 c 正在迭代列。

然后,只有在 c< = r
时才输出'*'
如果你在每一行的末尾,你还必须换新行。

[/ update]


* * *
* * *
* * * *
* * *
* *
*

What I have tried:

I've tried with for loop. But can't get the expected output.

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

    void main()
{
    int i,j;
    scanf("%d",&j);
    for(i=0;i<=j;i++)
    printf("*");
    for(i=j;i<=0;i--)
    printf("*");
}

解决方案

Quote:

I've tried with for loop. But can't get the expected output.

Try harder.

Try two nested loops (the outer loop for rows, the inner loop for columns).


[update]
Your code is not using nested loops.
Is is not using newlines as well.
Recipe for the first half of the pattern:

Suppose r is iterating over rows.
Suppose c is iterating over columns.
Then you have to output a '*' only if c<=r
You also have to put a newline if you are at the end of each row.
[/update]


这篇关于如何获得这样的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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