[SOLVED] CS135-Project 5 Arrays

24.99 $

Category:

Description

5/5 - (1 vote)

Problem 1

Write a program that asks the user to enter an NxM dimensional array containing single digit values (only the digits between 0 and 9) and counts the number of times each one of the 10 digits appears in the array. This program should:

  • Prompt the user to enter the sizes (number of rows and number of columns) of the array, and read in the dimensions given by the user
  • Prompt the user to enter the array row-by-row and read in each value (separated by spaces)
  • Display the total number of times each digit appears in the array
  • Display the 1D array containing the counts of each digit in one line
  • Display the 2D array that the user entered

The program should function as follows (items underlined are to be entered by the user):

 

This program counts occurrences of digits 0 through 9 in an NxM array.

Enter the size of the array (Row Column): 2 6

Enter row 0: 0 1 2 3 4 5

Enter row 1: 0 1 6 7 8 9 Total counts for each digit:

Digit 0 occurs 2 times

Digit 1 occurs 2 times

Digit 2 occurs 1 times

Digit 3 occurs 1 times

Digit 4 occurs 1 times

Digit 5 occurs 1 times

Digit 6 occurs 1 times

Digit 7 occurs 1 times

Digit 8 occurs 1 times

Digit 9 occurs 1 times

The digit counts directly from the 1D array:

2 2 1 1 1 1 1 1 1 1

The original 2D array entered by the user:

0 1 2 3 4 5

0 1 6 7 8 9