Write a C program that declares three one-dimensional arays named price, quantity, and amount. Each aray should be capable of holdinc
10 elements. Using a for loop, input values for the price and quantity rays. Theentries in the amount array should be product of the
corresponding values in the price and quantity arrays (thus,amountli=price[il*quantityli). After al of the data has been entered, display the
following output:
Quantity Price
Amount
Under each column heading display the appropriate value
定义三个一维数组,遍历数组输入和输出,
代码如下:
#include <stdio.h>
int main()
{
double price[10], amount[10];
int quantity[10], i;
for (i = 0; i < 10; i++)
{
printf("请输入第%d组数据(价格 数量):", i + 1);
scanf("%lf %d", &price[i], &quantity[i]);
amount[i] = price[i] * quantity[i];
}
printf("%10s %8s %8s\n", "Quantity", "Price", "Amount");
for (i = 0; i < 10; i++)
printf("%10d %8.2f %8.2f\n", quantity[i], price[i], amount[i]);
return 0;
}
#include <stdio.h>
void main()
{
double price[10];
int quantity[10];
double amount[10];
int i;
printf("please input 10 prices:\n");
for(i=0;i<10;i++)
scanf("%lf",&price[i]);
printf("please input 10 quantity:\n");
for(i=0;i<10;i++)
{
scanf("%d",&quantity[i]);
amount[i] = quantity[i] * price[i];
}
printf("%-15s%-15s%-15s\n","Price","Quantity","Amount");
for(int i=0;i<10;i++)
printf("%-15.1f%-15d%-15.1f\n",price[i],quantity[i],amount[i]);
return 0;
}
#include<stdio.h>
int main()
{
float price[10],quanity[10],amount[10];
int i;
printf("请输入价格和数量:\n");
for(i=0;i<10;i++)
{
scanf("%f",&price[i]);
scanf("%f",&quanity[i]);
}
for(i=0;i<10;i++)
amount[i]=price[i]*quanity[i];
for(i=0;i<10;i++)
printf("%f ",amount[i]);
return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!