C 数据类型示例
实际案例
以下是一个使用不同数据类型计算并输出若干物品总成本的实际案例:
示例
// 创建不同数据类型的变量
int items = 50;
float cost_per_item = 9.99;
float total_cost = items * cost_per_item;
char
currency = '$';
// 打印变量
printf("Number of items: %d", items);
printf("Cost per item: %.2f %c", cost_per_item, currency);
printf("Total cost = %.2f %c", total_cost, currency);
亲自试一试 »

