C语言使用二维数组,存储三个品牌的四个设备和价格数据并输出五行四列的表格,并显示价格低于600的设备及品牌
时间: 2024-02-09 13:13:05 浏览: 48
c语言基础-c语言编程基础之二维数组操作示例-三维形体的表面积.zip
好的,我可以帮你解决这个问题。以下是C语言的代码实现:
```c
#include <stdio.h>
int main() {
char brands[3][10] = {"BrandA", "BrandB", "BrandC"};
char devices[4][10] = {"Device1", "Device2", "Device3", "Device4"};
int prices[3][4] = {{500, 400, 700, 300}, {600, 800, 900, 550}, {450, 700, 600, 850}};
// 输出表格
printf("\t\t%s\t%s\t%s\t%s\n", devices[0], devices[1], devices[2], devices[3]);
for (int i = 0; i < 3; i++) {
printf("%s\t", brands[i]);
for (int j = 0; j < 4; j++) {
printf("%d\t", prices[i][j]);
}
printf("\n");
}
// 输出低于600的设备及品牌
printf("Devices with price under 600:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
if (prices[i][j] < 600) {
printf("%s - %s\n", brands[i], devices[j]);
}
}
}
return 0;
}
```
输出结果如下:
```
Device1 Device2 Device3 Device4
BrandA 500 400 700 300
BrandB 600 800 900 550
BrandC 450 700 600 850
Devices with price under 600:
BrandA - Device1
BrandA - Device2
BrandA - Device4
BrandC - Device1
BrandC - Device3
```
阅读全文