如何在C中创建以下模式? [英] How do I creat the following pattern in C?
本文介绍了如何在C中创建以下模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上*被替换为;
如果我们可以使用abs()来解决它,那么请解释一下;
Actually * was replaced by " " ;
If we can solve it using abs() then please explain it;
****1****
***1*1***
**1*2*1**
*1*3*3*1*
1*4*6*4*1
*1*3*3*1*
**1*2*1**
***1*1***
****1****
我尝试过:
What I have tried:
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,c=0;
for(i=5;i>=1;i--)
{
for(j=1;j<=9;j++)
{
if( (j>= i) && (j<= (c+i) ) )
{
printf("*");
}
else
{
printf(" ");
}
}
c=c+2;
printf("\n");
}
c=6;
for(i=2;i<=5;i++)
{
for(j=1;j<=9;j++)
{
if( (j>= i) && (j<= (c+i) ) )
{
printf("*");
}
else
{
printf(" ");
}
}
c=c-2;
printf("\n");
}
getch();
return 0;
}
推荐答案
这是HomeWork,所以只有建议。
模式是:
Pascal的三角形 - 维基百科,免费的百科全书 [ ^ ]
-try解决问题2个问题:
- 解决每行值的计算问题。
- 解决演示文稿
你需要记住前一行来计算下一个。
Nota:不需要abs()。
This is HomeWork, so only advices.
The pattern is:
Pascal's triangle - Wikipedia, the free encyclopedia[^]
-try to solve the problem as 2 problems:
- solve the computing of each rows values.
- Solve the presentation
you need to remember the previous row to compute the next one.
Nota: abs() is not needed.
这篇关于如何在C中创建以下模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文