一道有点难度的C语言题目 小弟在线等 急啊A supermarket conveyor belt holds a range of groceries. The price of each product is [ 60 120 5 13 ] ; while the numbers of each product are [ 3 4 2 1 ]. Write a C program that calculates an
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 06:40:49
一道有点难度的C语言题目 小弟在线等 急啊A supermarket conveyor belt holds a range of groceries. The price of each product is [ 60 120 5 13 ] ; while the numbers of each product are [ 3 4 2 1 ]. Write a C program that calculates an
一道有点难度的C语言题目 小弟在线等 急啊
A supermarket conveyor belt holds a range of groceries. The price of each product is [ 60 120 5 13 ] ; while the numbers of each product are [ 3 4 2 1 ]. Write a C program that calculates and prints the total bill.
Hint:
To declare a vector in C you need to specify its type. See how price is declared below.
int price[4] = {60, 120, 5, 13};
The first element of price is price[0], with value 60 (note that in C we use brackets to index the vector)
The second element of price is price[1], with value 120.
The third element of price is price[2], with value 5.
The last element of price is price[3], with value 13.
一道有点难度的C语言题目 小弟在线等 急啊A supermarket conveyor belt holds a range of groceries. The price of each product is [ 60 120 5 13 ] ; while the numbers of each product are [ 3 4 2 1 ]. Write a C program that calculates an
#include
void main()
{
int price[4] = { 60, 120, 5, 13 };
int num[4] = { 3, 4, 2, 1 };
int sum = 0;
for (int i = 0; i < 4; i++)
{
sum += price[i]*num[i];
}
printf("The total money is %d.\n", sum);
}
……难点何在?还是我理解错意思了?