若有以下银行卡信息 id和bonus请编写程序,从键盘输入5条银行卡记录,使用结构体数组存储这些数据,并按并按金额升序排序,输出排序后的结果。

struct card{
    int id;
    int bonus;
}a[5];
int main()
{
    int i,j,t;
    for(i=0;i<5;i++)
    {
        scanf("%d %d",&a[i].id,&a[i].bonus);
    }
        for(i=0;i<5;i++)
        {
            for(j=0;j<5-i-1;j++)
            {


            if(a[j].bonus>a[j+1].bonus)
                {
                    t=a[j].bonus;
                   a[j].bonus=a[j+1].bonus;
                   a[j+1].bonus=t;
                }
            }
        }

    for(i=0;i<5;i++){
    printf("%d %d\n",a[i].id,a[i].bonus);
    }
    return 0;
}
 

好的,我可以帮您编写这个程序。首先,我们需要定义一个结构体来表示每个员工的信息,包括姓名、基本工资、奖金、税金实发工资。可以按照如下方式定义: ```c struct Employee { char name[20]; float basic_salary; float bonus; float tax; float net_salary; }; ``` 然后,我们可以定义一个结构体数组来存放多个员工的信息。例如: ```c struct Employee employees[] = { {"Tom", 5000, 1000, 750, 5250}, {"Mary", 6000, 2000, 900, 7100}, // ... }; ``` 接下来,我们可以使用循环遍历结构体数组,依次输出每个员工的姓名实发工资。例如: ```c for (int i = 0; i < sizeof(employees) / sizeof(struct Employee); i++) { printf("%s 的实发工资是 %.2f 元\n", employees[i].name, employees[i].net_salary); } ``` 这样就可以依次输出每个员工的姓名实发工资了。完整的程序代码如下: ```c #include <stdio.h> struct Employee { char name[20]; float basic_salary; float bonus; float tax; float net_salary; }; int main() { struct Employee employees[] = { {"Tom", 5000, 1000, 750, 5250}, {"Mary", 6000, 2000, 900, 7100}, // ... }; for (int i = 0; i < sizeof(employees) / sizeof(struct Employee); i++) { printf("%s 的实发工资是 %.2f 元\n", employees[i].name, employees[i].net_salary); } return 0; } ``` 希望这个程序能够帮助您理解如何使用结构体数组来存放表中数据输出需要的信息。如果您有任何问题,可以随时向我提问。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值