C语言编程小练习4(嵌套循环)
4.1输入如下图所示的图案(注:星号之间没有空格)
1 #include<stdio.h>
2
3 int main(void)
4 {
5 int i, j;
6 for (i = 1; i <= 9; i++) {
7 for (j = 1; j <= 9 - i;j++)
8 printf(" ");
9 for (j = 1; j <= i; j++)
10 printf("*");
11 printf("\n");
12 }
13 return 0;
14 }
4.2根据输入的行数输出图案。例如:输入的行数为7,则输出如下图所示的图案(注:星号之间没有空格)。
PS:我在(ubuntu )GCC 5.4.0里编译如图代码时,出现以下警告。
具体原因如下:
The abs()
function is declared in <stdlib.h>
which you’ve not included.
GCC 4.9.2 didn’t complain because the default compilation mode was C89/C90 (-std=gnu89
) and functions did not need to be declared before being used in C89 as long as they returned an int
, but the default compilation mode was changed to C11 (-stdd=gnu11
) in GCC 5.1.0 (see the release notes) and in C11 functions must be declared (or defined) before they are used.
意思就是abs() 函数被声明在stdlib库里,而我没包含进去,改一下就好了;后面是解释GCC版本更新,编译模式改变,新版本在函数使用前必须先被声明。
1 #include<std