Answer to Question #150887 in C++ for russel estabaya

Question #150887
Write a program using two dimensional arrays that searches a number and display the number of times it occurs on the list of 12 input values.
1
Expert's answer
2020-12-14T04:58:21-0500
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
    // we declare an array for search a number among inputted 12 number
    int A[3][4];
    cout << "Enter 12 number: " << endl;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++) {
            int n;
            cin >> n;
            A[i][j] = n;
        }
    }
    cout << "the two dimensional array: " << endl;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++) {
            cout << setw(4) << A[i][j];
        }
        cout << endl;
    }
    int number;
    cout << "Enter a number for search: ";
    cin >> number;
    int times = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++) {
            if (A[i][j] == number) {
                times++;
            }
        }
    }
    cout << "\nThe occurence of " << number << " is " << times << " times" << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog