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
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:
Comments
Thank u so much! God bless
Leave a comment