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