#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;
}
Comments
Leave a comment