Write a C program that stores the following numbers in an array named prices: 9.
ID: 3565871 • Letter: W
Question
Write a C program that stores the following numbers in an array named prices: 9.92, 6.32, 12.63, 5.95, and 10.29. Your program should also create two arrays named items and amounts, each capable of storing five double-precision numbers. Using a for loop and scanf(), have your program accept five user-input numbers in
the items array when the program is run. Your program should store the product of the corresponding
values in the prices and items array in the amounts array. Your program should then display the following
output for each entry:
Items Price Amount
Also, include the total amount at the very bottom of the table. Make sure the table is nicely formatted.
Explanation / Answer
#include<stdio.h>
#include<math.h>
int main()
{
int i;
double prices[5]={9.92, 6.32, 12.63, 5.95,10.29};
double items[5], amounts[5], total=0;
for(i=0;i<5;i++)
{
printf("Enter number of items of type %d ",i+1);
scanf("%lf",&items[i]);
amounts[i]=prices[i]*items[i];
total+=amounts[i];
}
printf("Items Price Amount ");
for(i=0;i<5;i++)
{
printf("%f %f %f ",items[i],prices[i],amounts[i]);
}
printf("Total amount = %f",total);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.