C语言使用二维数组,存储三个品牌和四个设备以及价格,输出五行四列表格,并输出价格低于600的品牌设备价格
时间: 2023-12-25 20:06:59 浏览: 64
好的,这是你的问题:C语言使用二维数组,存储三个品牌和四个设备以及价格,输出五行四列表格,并输出价格低于600的品牌设备价格。
以下是示例代码:
```c
#include <stdio.h>
int main() {
// 二维数组存储品牌、设备和价格
int prices[3][4] = {
{200, 300, 400, 500},
{250, 350, 450, 550},
{100, 150, 600, 700}
};
// 输出五行四列表格
printf("\t\tDevice 1\tDevice 2\tDevice 3\tDevice 4\n");
for (int i = 0; i < 3; i++) {
printf("Brand %d:\t", i+1);
for (int j = 0; j < 4; j++) {
printf("$%d\t\t", prices[i][j]);
}
printf("\n");
}
// 输出价格低于600的品牌设备价格
printf("\nPrices below $600:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
if (prices[i][j] < 600) {
printf("Brand %d, Device %d: $%d\n", i+1, j+1, prices[i][j]);
}
}
}
return 0;
}
```
输出结果如下:
```
Device 1 Device 2 Device 3 Device 4
Brand 1: $200 $300 $400 $500
Brand 2: $250 $350 $450 $550
Brand 3: $100 $150 $600 $700
Prices below $600:
Brand 1, Device 1: $200
Brand 1, Device 2: $300
Brand 1, Device 3: $400
Brand 1, Device 4: $500
Brand 2, Device 1: $250
Brand 2, Device 2: $350
Brand 2, Device 3: $450
Brand 3, Device 1: $100
Brand 3, Device 2: $150
```
阅读全文