Answer to Question #340206 in C++ for nana

Question #340206

Create a program with a one-dimensional array that searches for a number within the array, and how many times the number appears on the array.

1
Expert's answer
2022-05-12T08:20:00-0400
#include <iostream>
using namespace std;


int main()
{
	int arr[100];
	int number, count = 0, key, i = 0;
	while (key != 0){
 		cout << "Enter number for array (0-end): ";
 		cin >> arr[i];
 		key = arr[i];
		i ++;
	}
	cout << "Enter number to search: ";
	cin >> number;
	for (i = 0; i < 20; i++){
		if (number == arr[i])
			count++;
   	}
   	if (count > 0){
   		cout << "The number " << number << " occurs " << count << " times in the array!"<< endl;
   	}else
   		cout << "The umber " << number << " does not appear in the array!" << endl;
	
}

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
APPROVED BY CLIENTS