Friday, August 14, 2026

Warehouse Revenue Calculation || C Lab Programs

Program 11: Calculate total warehouse revenue per branch.

Problem Statement:: A small warehouse tracks many units of different products shipped from multiple branches. Another dataset shows how much revenue each product generates per unit. Develop a C program that combines these datasets to calculate the total revenue generated by each branch.

Problem Description:

  • Input: Number of branches, number of products, a 2D array of units shipped, and a 1D array of revenue per product unit.

  • Output: The total revenue calculated for each branch.

  • Constraints: All counts, units, and revenue values must be non-negative integers.

  • Method: Store shipment data in a 2D array and product revenue in a 1D array; multiply and accumulate to find totals.

Pgm Logic:

  1. Start.

  2. Input the number of branches and products.

  3. Declare a 2D array units[branches][products] and a 1D array revenue[products].

  4. Input shipment units for each branch and product.

  5. Input revenue per unit for each product.

  6. For each branch i:

    • Initialize total = 0.

    • For each product j:

      • Calculate total += units[i][j] * revenue[j].

    • Print the total revenue for branch i.

  7. Stop.

Program Code:

// Purpose: To combine shipment and revenue datasets using arrays to calculate total revenue per branch.

#include <stdio.h>


int main() {

    int branches, products, i, j;

    printf("Enter number of branches: ");

    scanf("%d", &branches);

    printf("Enter number of products: ");

    scanf("%d", &products);

    int units[branches][products];

    int revenue[products];

    printf("\nEnter number of units shipped by each branch for each product:\n");

    for(i = 0; i < branches; i++) {

        printf("Branch %d:\n", i+1);

        for(j = 0; j < products; j++)

            scanf("%d", &units[i][j]);

    }

    printf("\nEnter revenue per unit for each product:\n");

    for(j = 0; j < products; j++) {

        printf("Product %d revenue: ", j+1);

        scanf("%d", &revenue[j]);

    }

    printf("Total revenue per branch:\n");

    for (i = 0; i < branches; i++) {

        int total = 0;

        for (j = 0; j < products; j++)

            total += units[i][j] * revenue[j];

        printf("Branch %d: %d\n", i + 1, total);

    }

    return 0;

}


Output: 

Enter number of branches: 3 

Enter number of products: 2 

(Enter units: 20, 10; 20, 30; 50, 20) 

(Enter revenue: 20, 30) 

Total revenue per branch: Branch 1: 700 Branch 2: 1300 Branch 3: 1600

RESULT: Thus the program has been executed and the output was verified.

Remarks: Compiled and run in Code::Blocks. This program illustrates the practical application of matrix-like data processing in business scenarios.

Program Explanation: The 2D array acts as a table where rows are branches and columns are products. The program iterates through each branch (row) and multiplies each shipment count by its corresponding unit price from the 1D revenue array to derive a sum for that branch.


For all 2026 published C Lab Program posts Index page: click here

For all 2026 published articles list: click here

…till the next post, bye-bye & take care

No comments:

Post a Comment