下面是一个图书的单价表:1、计算概论 289 元本2、数据结构与算法 327 元本3、数字逻辑 456 元本4、C++程序设计教程 78 元本5、人工智能 35 元本6、计算机体系结构 862 元本7、编译原理 278 元本8、操作系统 43 元本9、计算机网络 56 元本10、JAVA程序设计 65 元本给定每种图书购买的数量编程计算应付的总费用。输入描述输入一行包含 10 个整数大于等于 0小
#include <iostream>
#include <iomanip>
int main() {
double price[] = {28.9, 32.7, 45.6, 78, 35, 86.2, 27.8, 43, 56, 65};
int quantity[10];
double total = 0;
for (int i = 0; i < 10; i++) {
std::cin >> quantity[i];
total += price[i] * quantity[i];
}
std::cout << std::fixed << std::setprecision(1) << total << std::endl;
return 0;
}
原文地址: http://www.cveoy.top/t/topic/h7XN 著作权归作者所有。请勿转载和采集!