C语言:说明:n 为正整数,是直角三角形的高度和底边宽度。s 为符号,是组成图形的字符。 输出格式 n 行由 s 组成的直角三角形(参见输出样例)
时间: 2023-06-01 17:01:26 浏览: 218
以下是C语言的代码实现:
```c
#include <stdio.h>
int main() {
int n;
char s;
scanf("%d %c", &n, &s); // 输入 n 和 s
for (int i = 1; i <= n; i++) { // 外层循环控制行数
for (int j = 1; j <= i; j++) { // 内层循环控制每行的字符数
printf("%c", s);
}
printf("\n"); // 每行输出完毕后换行
}
return 0;
}
```
在代码中,我们首先通过 `scanf` 函数输入 `n` 和 `s`。然后,使用两个嵌套的循环,外层循环控制行数,内层循环控制每行的字符数。在内层循环中,我们使用 `printf` 函数输出字符 `s`。每行输出完毕后,使用 `printf` 函数输出一个换行符,进入下一行的输出。最后,程序返回 0,表示正常结束。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)