Finding total number of each Product sold and total product sold by each Person

Question: A multinational company has hired 3 sales persons for selling its 3 different products in a City. 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 product and the total sells of each sales-person. Use Arrays.

Program


#include<stdio.h>
#include<conio.h>

int main()
{
 int arr[3][3], i, j, productSale[3], personSale[3];
 clrscr();

 /* Reading */
 for(i=0; i < 3; i++)
 {
  for(j=0; j < 3; j++)
  {
   printf("Enter number of product-%d sold by person-%d:\n",j+1, i+1);
   scanf("%d", &arr[i][j]);
  }
 }
 /* Calculation */
 for(i=0;i< 3; i++)
 {
  productSale[i] = 0;
  personSale[i] = 0;
  for(j=0; j< 3; j++)
  {
   personSale[i] += arr[i][j];
   productSale[i] += arr[j][i];
  }
 }
 /* Displaying each product sold */
 printf("Details of each product sold is:\n");
 for(i=0;i < 3; i++)
 {
  printf("Product-%d = %d\n",i+1, productSale[i]);
 }
 /* Displaying total product sold by each person*/
 printf("Details of total product sold by each person is:\n");
 for(i=0;i < 3; i++)
 {
  printf("Person-%d = %d\n",i+1, personSale[i]);
 }

 getch();
 return 0;
}

Output of above program:

Enter number of product-1 sold by person-1:
1 ↲
Enter number of product-2 sold by person-1:
2 ↲
Enter number of product-3 sold by person-1:
3 ↲
Enter number of product-1 sold by person-2:
4 ↲
Enter number of product-2 sold by person-2:
5 ↲
Enter number of product-3 sold by person-2:
6 ↲
Enter number of product-1 sold by person-3:
7 ↲
Enter number of product-2 sold by person-3:
8 ↲
Enter number of product-3 sold by person-3:
9 ↲
Details of each product sold is:
Product-1 = 12
Product-2 = 15
Product-3 = 18
Details of total product sold by each person is:
Person-1 = 6
Person-2 = 15
Person-3 = 24


Note: ↲ indicates ENTER is pressed.