一道有点难度的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/06/27 11:45:53
![一道有点难度的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](/uploads/image/z/12879738-18-8.jpg?t=%E4%B8%80%E9%81%93%E6%9C%89%E7%82%B9%E9%9A%BE%E5%BA%A6%E7%9A%84C%E8%AF%AD%E8%A8%80%E9%A2%98%E7%9B%AE+%E5%B0%8F%E5%BC%9F%E5%9C%A8%E7%BA%BF%E7%AD%89+%E6%80%A5%E5%95%8AA+supermarket+conveyor+belt+holds+a+range+of+groceries.++The+price+of+each+product+is+%5B+60+120++5+13+%5D+%3B+while+the+numbers+of+each+product+are+%5B+3+4+2+1+%5D.++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 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);
}
……难点何在?还是我理解错意思了?