C语言99乘法表上三角
时间: 2023-12-05 21:31:59 浏览: 137
以下是C语言实现九九乘法表上三角的代码:
```c
#include <stdio.h>
int main()
{
int i, j;
for (i = 1; i <= 9; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d*%d=%d ", j, i, i*j);
}
printf("\n");
}
return 0;
}
```
输出结果为:
```
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
```
相关问题
c语言99乘法表代码三角
以下是C语言实现九九乘法表的代码:
```c
#include <stdio.h>
int main() {
int i, j;
for (j = 1; j <= 9; j++) {
for (i = 1; i <= j; i++) {
printf("%d*%d=%-4d", i, j, i * j);
}
printf("\n");
}
return 0;
}
```
这段代码使用嵌套的循环来打印九九乘法表。外层循环控制行数,内层循环控制每行的列数。通过printf函数打印每个乘法表达式,并使用%-4d来保持对齐。最后使用printf("\n")来换行。
c语言99乘法表正倒三角
以下是C语言中打印九九乘法表正倒三角的代码示例:
正三角靠右:
```c
#include <stdio.h>
int main() {
int a, n, b;
printf("正三角靠右:\n\n");
for (a = 1; a < 10; a++) {
for (n = 9; n > a; n--) {
printf(" ");
}
for (b = 1; b <= a; b++) {
printf("%d*%d=%2d\t", a, b, a * b);
}
printf("\n");
}
return 0;
}
```
倒三角靠右:
```c
#include <stdio.h>
int main() {
int a, n, b;
printf("倒三角靠右:\n\n");
for (a = 1; a < 10; a++) {
for (n = 1; n < a; n++) {
printf(" ");
}
for (b = 9; b >= a; b--) {
printf("%d*%d=%2d\t", a, b, a * b);
}
printf("\n");
}
return 0;
}
```
以上代码可以在C语言中打印出九九乘法表的正倒三角形式。
#### 引用[.reference_title]
- *1* [c语言:九九乘法表 | 正三角形 | 倒三角形](https://blog.csdn.net/xinanbo/article/details/113175807)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [C语言中的输出99乘法表4种方法](https://blog.csdn.net/qq_43178535/article/details/126963299)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]