您的位置:首页 > 编程语言 > C语言/C++

重头学起C语言(GCC,VI,C++,GDB)【三】

2010-02-13 10:49 197 查看
结构体

1.

struct payment {

    char *name;

    float salary;

   
float subsidy;

}clerk={"Karlis",150.20,30.0};
main()

{

    float sum(struct payment *);

   
printf("clerk %s has a total wage/n

        $%.2f./n",sum(&clerk)
);

}

float sum(struct payment *wage
)

{

   
return(wage->salary+wage->subsidy);

}
2.
main()

{

    float sum(struct payment *);

    printf("The total money
is/n

        $%.2f/n",sum(clerk)
);

}

float
sum(struct payment *wage
)

{struct payment
*wage;

    float total;

    int i;

   
for(i=0,total=0;i<2;i++,wage++)

       
total+=wage->salary+wage->subsidy;

    return(total);

}
 
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息