如何获得这样的输出? [英] How to get a output like this?
问题描述
* *
* * *
* * * *
* * *
* *
*
我的尝试:
我试过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:
Supposer
is iterating over rows.
Supposec
is iterating over columns.
Then you have to output a'*'
only ifc<=r
You also have to put a newline if you are at the end of each row.
[/update]
这篇关于如何获得这样的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!