Answer to Question #303002 in C++ for Jive

Question #303002

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


1
Expert's answer
2022-02-26T05:51:50-0500

SOLUTION CODE


#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;
}



Sample output:



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

Jive
26.02.22, 13:46

Thank u so much! God bless

Leave a comment

LATEST TUTORIALS
New on Blog