1、定义一个结构体类型book,成员有书名bName,定价fPrice,数量count, 定义N个
发布网友
发布时间:2022-10-28 22:25
我来回答
共1个回答
热心网友
时间:2023-10-09 11:19
#include <stdio.h>
typedef struct book
{
float fPrice;
unsigned int count;
const char *bName;
} book;
int main(int argc, char const *argv[])
{
book books[] = {
{ "hello", 1, 2 },
{ "world", 2, 3 },
{ "byebye", 3.3, 4}
};
double sum = 0;
int i = 0;
for (i = 0; i < 3; ++i)
{
sum += books[i].fPrice * books[i].count;
}
printf("%.2lf\n", sum);
return 0;
}