Write a two dimensional arrays that searches a number and display the number of times it occurs on the list of 12 input values. Sample input/output dialogue: Enter twelve numbers: 15 20 12 30 35 40 16 18 20 18 20 Enter a number to search: 20 Occurrence(s): 3
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
#include<iostream>
using namespace std;
int main()
{
//declare an array of size 12
int arr[12];
cout<<"Enter 12 Numbers:\n ";
for( int i=0; i<12; i++)
cin>>arr[i];
cout<<"\nEnter a number to search: ";
int search_number;
cin>>search_number;
int search_number_occurences = 0;
for(int i=0; i<12; i++)
{
if(arr[i]==search_number)
{
search_number_occurences = search_number_occurences + 1;
}
}
cout<<"Occurences: "<<search_number_occurences<<endl;
return 0;
}