崔渭阳 2023-06-02 20:31 采纳率: 66.7%
浏览 44
已结题

关于#c语言#的问题,请各位专家解答!段错误


#include<stdio.h>
struct worker{
    char name[10];
    double salary;
    double other;
    double cost;
    double end;
};
int main(){
    int n,i;
    struct worker pople[10];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s %lf %lf %lf", &pople[i].name, &pople[i].salary, &pople[i].other, &pople[i].cost);
        pople[i].end=(pople[i].salary+pople[i].other)-pople[i].cost;
        
    }
    for(i=0;i<n;i++){
        printf("%s %.2f\n",pople[i].name,pople[i].end);
    }
   
    return 0;
}

img

  • 写回答

3条回答 默认 最新

  • 滴水不穿石 2023-06-02 21:17
    关注
    //试试这样看行不行。不清楚你题目要求,看你的代码貌似n有点问题。
    
    
    #include <stdio.h>
    struct worker
    {
        char name[10];
        double salary;
        double other;
        double cost;
        double end;
    };
    int main()
    {
        int n, i;
        scanf("%d", &n);
        struct worker pople[n];
        for (i = 0; i < n; i++)
        {
            scanf("%s %lf %lf %lf", pople[i].name, &pople[i].salary, &pople[i].other, &pople[i].cost);
            pople[i].end = (pople[i].salary + pople[i].other) - pople[i].cost;
        }
        for (i = 0; i < n; i++)
        {
            printf("%s %.2lf\n", pople[i].name, pople[i].end);
        }
        return 0;
    }
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月1日
  • 已采纳回答 9月23日
  • 创建了问题 6月2日

悬赏问题

  • ¥20 python忆阻器数字识别
  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真