用c语音编写程序,输出N件航材中价值最高航材的信息。N用符号常量定义为5,航材信息包括件号(PN)、名称(Designation)、单价(Price)。注意:件号为长整型,名称是没有空格的字符串,最长不超过30个字符,单价为float类型。使输出结果为20002 Ty89 900
时间: 2024-02-13 21:06:22 浏览: 38
好的,我明白了。以下是用 C 语言编写的程序,可以输出 N 件航材中价值最高航材的信息,其中 N 被定义为 5,航材信息包括件号、名称、单价。
```c
#include <stdio.h>
#include <string.h>
#define N 5
typedef struct {
long PN;
char Designation[31];
float Price;
} Aircraft;
int main() {
Aircraft aircraft[N];
int i, j;
// 输入航材信息
for (i = 0; i < N; i++) {
printf("请输入第%d件航材的信息:\n", i+1);
printf("PN:");
scanf("%ld", &aircraft[i].PN);
printf("Designation:");
scanf("%s", aircraft[i].Designation);
printf("Price:");
scanf("%f", &aircraft[i].Price);
}
// 计算价值最高的航材
int max_index = 0;
float max_value = aircraft[0].Price;
for (i = 1; i < N; i++) {
if (aircraft[i].Price > max_value) {
max_index = i;
max_value = aircraft[i].Price;
}
}
// 输出价值最高的航材信息
printf("\n价值最高的航材信息为:\n");
printf("PN:%ld\n", aircraft[max_index].PN);
printf("Designation:%s\n", aircraft[max_index].Designation);
printf("Price:%g\n", aircraft[max_index].Price);
return 0;
}
```
如果你想让程序输出 20002 Ty89 900,可以按照以下方式输入航材信息:
```
请输入第1件航材的信息:
PN:20001
Designation:Ty11
Price:500
请输入第2件航材的信息:
PN:20002
Designation:Ty89
Price:900
请输入第3件航材的信息:
PN:20003
Designation:Ty22
Price:700
请输入第4件航材的信息:
PN:20004
Designation:Ty33
Price:200
请输入第5件航材的信息:
PN:20005
Designation:Ty44
Price:100
```
这样程序就会输出以下结果:
```
价值最高的航材信息为:
PN:20002
Designation:Ty89
Price:900
```
希望能够帮到你。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)