double subscript array assignment and solution, Exercises of C programming

Double subscripted array that receives the number of the employee and what/how much product they sold last month, then display them on a 2D table with their total at the last column for how much the employee has sold, and for the last row for each product.

Typology: Exercises

2018/2019

Uploaded on 12/15/2019

mrmknitro
mrmknitro 🇱🇧

1 document

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Solution: 6.22 on C language
#include<stdio.h>
#include<iostream>
void getSales(float[][5]);
void printHeader(void);
void printSales(float[][5]);
pf3
pf4
pf5

Partial preview of the text

Download double subscript array assignment and solution and more Exercises C programming in PDF only on Docsity!

Solution: 6.22 on C language

#include<stdio.h> #include void getSales(float[][5]); void printHeader(void); void printSales(float[][5]);

int main(void) { /* declare and initialize the array / float sales[4][5] = { 0.0 }; / call the function to read in the sales from the user/ getSales(sales); /call the function to display the table header / printHeader(); / call the function to display the sales */ printSales(sales); system("pause"); return 0; } /***** getSales **********

  • Description: reads sales figures in from the user
  • until the user enters -
  • Parameters: 2-dimensional float array (4 X 5)
  • Return Type: void *****************/ void getSales(float sales[][5]) { int salesPerson; int product;

printf("Sales-%30s\n", "Products"); printf("person %8d%8d%8d%8d%8d%9s\n", 1, 2, 3, 4, 5, "Total"); } /***** printSales **********

  • Description: displays the sales and summaries
  • Parameters: 2-dimensional float array
  • Return Type: void *****************/ void printSales(float sales[][5]) { float totalSales; int i, j; float productSales[5] = { 0.0 }; for (i = 0; i < 4; i++) { totalSales = 0.0; printf("%3d ", i + 1); for (j = 0; j < 5; j++) { totalSales += sales[i][j]; productSales[j] += sales[i][j]; printf("%8.2f", sales[i][j]); }

printf("%8.2f\n", totalSales); } printf("Total "); for (j = 0; j < 5; j++) printf("%8.2f", productSales[j]); printf("\n"); }