【发布时间】:2017-10-28 21:08:12
【问题描述】:
我正在尝试创建一个函数,该函数允许在从主函数调用时打印不同大小的树。不幸的是,当我运行我的代码时,我在主函数中收到了三次错误“参数类型'void'不完整”。这是我的代码:
#include <stdio.h>
void tree(int rows)
{
int i, j;
for(i=1; i<=rows; i++)
{
for(j=i; j<rows; j++)
{
printf(" ");
}
for(j=1; j<=(2*i-1); j++)
{
printf("*");
}
printf("\n");
}
}
int main()
{
int rows;
rows = 5;
printf("%d\n", tree(rows));
rows = 3;
printf("%d\n", tree(rows));
rows = 6;
printf("%d\n", tree(rows));
}
如果有任何建议,我将不胜感激!
【问题讨论】:
-
您的 printf 期望返回类型为 int,但是,树返回 void。
-
所以我需要更改 %d?
-
main中的printf应该显示什么信息? -
我不知道你为什么在 main 中调用 printf,但是可以通过直接在 main 中调用 tree 来调用它。
-
是的,我明白了我现在在做什么,感谢您的帮助!
标签: c