c programing sohe he following problem A company has four a
c programing
Solution
/* Cprogramme */
// C program to displauy sales statistics using 2 dimentional array.
#include <stdio.h>
const int nosp = 4; //number of salespersonns
const int nop = 5; //number of products
int main()
{
int sum=0,productsum=0;
int sales_stats[nosp][nop];
int i,j;
// Loop for reading data for each salesperson,prodct wise
for (i = 0; i < nosp; ++i) {
for(j = 0; j < nop; ++j) {
printf(\"Enter Salesperson %d Sales of Product %d: \", i+1, j+1); //prompt for input data
scanf(\"%d\", &sales_stats[i][j]); //read for input data
}
}
// Display Output as criteria format
printf(\"\ Summery of Sales: \ \ \");
printf(\"\\t\\tProduct1\\tProduct2\\tProduct3\\tProduct4\\tProduct5\\tSum\ \");
for (i = 0; i < nosp; ++i) {
printf(\"\ Salesperson%d\", i+1);
sum=0;
for(j = 0; j < nop; ++j)
{
sum=sum+sales_stats[i][j]; //summation of row wise each sales person sale of all products
printf(\"\\t%d\\t\", sales_stats[i][j]); //dispaly row wise each sales person sale of all products
}
printf(\"%d\\t\",sum); //display sum of all products of each sales person
}
//loop to dispaly product sum
printf(\"ProductSum\");
for (i = 0; i < nop; ++i) {
productsum=0;
for(j = 0; j < nosp; ++j)
{
productsum=productsum+sales_stats[j][i]; //summation of column wise each product sale of all salespersons
}
printf(\"\\t%d\\t\", productsum); //display productsum
}
return 0;
}
Sample Output :
Enter Salesperson 1 Sales of Product 1: 100
Enter Salesperson 1 Sales of Product 2: 120
Enter Salesperson 1 Sales of Product 3: 210
Enter Salesperson 1 Sales of Product 4: 50
Enter Salesperson 1 Sales of Product 5: 15
Enter Salesperson 2 Sales of Product 1: 120
Enter Salesperson 2 Sales of Product 2: 40
Enter Salesperson 2 Sales of Product 3: 30
Enter Salesperson 2 Sales of Product 4: 50
Enter Salesperson 2 Sales of Product 5: 50
Enter Salesperson 3 Sales of Product 1: 50
Enter Salesperson 3 Sales of Product 2: 100
Enter Salesperson 3 Sales of Product 3: 100
Enter Salesperson 3 Sales of Product 4: 120
Enter Salesperson 3 Sales of Product 5: 80
Enter Salesperson 4 Sales of Product 1: 30
Enter Salesperson 4 Sales of Product 2: 250
Enter Salesperson 4 Sales of Product 3: 75
Enter Salesperson 4 Sales of Product 4: 45
Enter Salesperson 4 Sales of Product 5: 20
Summery of Sales:
Product1 Product2 Product3 Product4 Product5 Sum
Salesperson1 100 120 210 50 15 495
Salesperson2 120 40 30 50 50 290
Salesperson3 50 100 100 120 80 450
Salesperson4 30 250 75 45 20 420
ProductSum 300 510 415 265 165
--------------------------------

