- 2071 Shrawan · 6 marks
Sales of products by sales-persons
Short answer
Use a 3x3 array for sales data (rows: salespersons, columns: products). While reading each entry, add it to row and column accumulators. Then display each product total (column sum) and each salesperson total (row sum).
A multinational company has hired 3 sales persons for marketing/selling its 3 different products in Kathmandu. Each sales person sells each of these products. Write a program to read number of each product sold by all sales-persons. Calculate total sells of each item and the total sells of each sales-person. Use arrays.
Assumptions. Three sales persons (rows) and three products (columns). A 3×3 array sold[i][j] holds the number of product j sold by person i. Two 1D arrays hold the totals: personTotal[i] (row sum) and prodTotal[j] (column sum). Both are updated while reading each value.
#include <stdio.h>
int main(void)
{
int sold[3][3], prodTotal[3] = {0}, personTotal[3] = {0};
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
printf("Units of product %d sold by salesperson %d: ", j + 1, i + 1);
scanf("%d", &sold[i][j]);
personTotal[i] += sold[i][j];
prodTotal[j] += sold[i][j];
}
printf("\n");
for (int j = 0; j < 3; j++)
printf("Total sales of product %d = %d\n", j + 1, prodTotal[j]);
for (int i = 0; i < 3; i++)
printf("Total sales of salesperson %d = %d\n", i + 1, personTotal[i]);
return 0;
}
Sample run
Input (entered one after another): 10 20 30 5 15 25 8 12 16
Total sales of product 1 = 23
Total sales of product 2 = 47
Total sales of product 3 = 71
Total sales of salesperson 1 = 60
Total sales of salesperson 2 = 45
Total sales of salesperson 3 = 36
Check: row totals 60 + 45 + 36 = 141 and product totals 23 + 47 + 71 = 141.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Correct program: character arrays · Computer Programming, chapter 7
- RECORD.txt item cost with VAT · Computer Programming, chapter 10
- Read records until end; show nth record · Computer Programming, chapter 10 · asked 2×
- Array overflow/underflow; add two arrays · Computer Programming, chapter 7
- Complex number multiplication using structure · Computer Programming, chapter 8
- GOTO types; sum of series program · Computer Programming, chapter 11
- Plan IS for marketing company · Information System, chapter 5
- Number of persons from reverberation time · Engineering Physics, chapter 3 · asked 2×
- Marketing strategies, pricing and credit policy · Entrepreneurship Development, chapter 5
- Resolution: American sells weapons · Artificial Intelligence, chapter 4 · asked 2×