对已编写的C语言进行修改时遇到的问题~

来源:百度知道 编辑:UC知道 时间:2024/06/23 01:05:35
実行结果是
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*********************
|*|
|*|
|*|

以下是我编写的程序
#include <stdio.h>
6: main() {
7: int k,i;
8:
9: printf(" *\n");
10: printf(" ***\n");
11: printf(" *****\n");
12: printf(" *******\n");
13: printf(" *********\n");
14: printf(" ***********\n");
15: printf(" *************\n");
16: printf(" ***************\n");
17: printf(" *****************\n");
18: printf(" *******************\n");

#include <stdio.h>
我感觉不用字符型char啊,能给出你们老师给的框架吗?
*号可以用个循环打
int main(void)
{
int i,j;

for(i=1;i<=11;i++)
{
for(j=1;j<=(i*2-1);j++)

{
printf("*");
}
printf("\n");
}
for (i=1; i<=3; i++)
{
printf(" |*|\n");
}
return 0;
}

}

char 定义字符变量
呵呵你们老师大概让你不要用那么多的printf,用个循环。

char其实也是以整型方式存储的
你直接把int改成char ,一切运行正常。