In: Computer Science
A customer has purchased 15 items in a department store. Write a code segment to read the unit price and the quantity of each these 15 items and to compute and print its price (which is the unit price times the quantity). Also compute and print average price of the 15 items.
program in c language ;
#include
int main()
{
int sum=0,a=0,b=0,quantity=0;
int i;
float avg=0;
for (i=1;i<=15;i++)
{
printf("enter price and quantity of item %d
:\n",i);
scanf("%d\n%d",&a,&b);
sum += (a*b);
quantity += b;
}
avg = sum/(float)15;
printf("the total price is %d \n the average price is
%.2f\n",sum,avg);
return 0;
}