Use MatLab to solve
Given matrix Price = [ 10, 20, 15, 27, 30, 25]
Quantity = [100, 50, 75, 40, 80, 75]
Question: 1. find the average price
2. find how many items are sold above the average price
3. Find the total income from transaction whose price is above the average price found in (1) above
3. find total income from transactions whose price is above the average price
Price = [ 10, 20, 15, 27, 30, 25]; Quantity = [100, 50, 75, 40, 80, 75]; % Part 1 avg = 0; for i=1:length(Price) avg = avg + Price(i); end avg = avg / length(Price); fprintf("Average price = %.2f\n",avg); % Part 2 aboveAvg = 0; for i=1:length(Price) if(Price(i)>avg) aboveAvg = aboveAvg + 1; end end fprintf("Number of items are sold above the average price = %d\n",aboveAvg); % Part 3 and 4 totalPrice = 0; for i=1:length(Price) if(Price(i)>avg) totalPrice = totalPrice + (Price(i)*Quantity(i)); end end fprintf("Total income from transaction whose price is above the average price found = %.2f\n",totalPrice);
Get Answers For Free
Most questions answered within 1 hours.