C语言编程小练习4(嵌套循环)

C语言编程小练习4(嵌套循环)

4.1输入如下图所示的图案(注:星号之间没有空格)
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值