---
title: "Sales of products by sales-persons"
subject: "Computer Programming"
chapter: 7
key: "semester_1/computer_programming:sales-persons-products-array"
source: https://www.bctengineer.com/q/semester_1/computer_programming/sales-persons-products-array
site: BCT Engineering
---

# Sales of products by sales-persons

Computer Programming · Chapter 7: Arrays and Strings

- Asked in: 2071 Shrawan, 6 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/sales-persons-products-array
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-7

## Question

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.

## 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).

## Answer

**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.

```c
#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`

```text
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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How are the sales data stored in the program?
   A. A 3x3 array with rows as products and columns as salespersons
   B. A 3x3 array sold[i][j]: row = salesperson, column = product
   C. A single 1D array of 9 totals
   D. Three separate char arrays
   Answer: B. sold[i][j] holds product j sold by person i. (Key point: Array layout)

2. Which total is personTotal[i]?
   A. The sum of column i
   B. The sum of row i (all products sold by person i)
   C. The sum of the whole array
   D. The largest value in row i
   Answer: B. A person's total is the sum across the row. (Key point: Row sum)

3. How are both totals computed?
   A. Only after all input, using a sort
   B. personTotal is computed but prodTotal needs a separate program
   C. They are typed in by the user
   D. Both are updated with += while each value is read
   Answer: D. personTotal[i] += sold[i][j] and prodTotal[j] += sold[i][j] run inside the nested loops. (Key point: Update method)

4. For input 10 20 30 5 15 25 8 12 16, what is the total of product 2?
   A. 60
   B. 23
   C. 47
   D. 45
   Answer: C. Column 2 is 20 + 15 + 12 = 47. (Key point: Sample check)

5. What does the check 60+45+36 = 23+47+71 = 141 show?
   A. The array has 141 elements
   B. Product 1 outsold every salesperson
   C. Only the person totals are correct
   D. Row totals and column totals both add up to the same grand total
   Answer: D. Both sums cover every entry once, so they must equal the grand total. (Key point: Consistency check)

## Related in Computer Programming

- [Correct program: character arrays](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Acorrect-program-char-arrays) — Computer Programming, chapter 7
- [RECORD.txt item cost with VAT](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-record-txt-invoice) — Computer Programming, chapter 10
- [Read records until end; show nth record](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-worker-nth-record) — Computer Programming, chapter 10, asked 2×
- [Array overflow/underflow; add two arrays](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aarray-overflow-underflow-add) — Computer Programming, chapter 7
- [Complex number multiplication using structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-complex-multiply) — Computer Programming, chapter 8
- [GOTO types; sum of series program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-goto-types-series) — Computer Programming, chapter 11

## Related in other subjects

- [Plan IS for marketing company](https://www.bctengineer.com/question.md?key=semester_8%2Finformation_system%3Amarketing-company-is-plan) — Information System, chapter 5
- [Number of persons from reverberation time](https://www.bctengineer.com/question.md?key=semester_1%2Fengineering_physics%3Areverberation-persons-present-hall) — Engineering Physics, chapter 3, asked 2×
- [Marketing strategies, pricing and credit policy](https://www.bctengineer.com/question.md?key=semester_7%2Fentrepreneurship_development%3Amarketing-strategy-price-credit) — Entrepreneurship Development, chapter 5
- [Resolution: American sells weapons](https://www.bctengineer.com/question.md?key=semester_6%2Fartificial_intelligence%3Aresolution-american-criminal) — Artificial Intelligence, chapter 4, asked 2×
