Using an array , write a C++ program that can hold ten integer input from user. Display those values on the screen , and their prompt the user an integer to search within the array , and count the number of times the item is found.
Enter 10 values in array :
1
2
3
4
5
6
7
8
8
Values in array now : 1 2 3 4 5 6 7 8 8
Enter the value to find : 8
8 was found in 2 times.
____________________________
Process excited with return value 0
Press any key continue . . .
#include <iostream>
using namespace std;
int main()
{
int arr[10];
cout << "Enter 10 values in array :";
for (int i = 0; i < 10; i++)
{
cin >> arr[i];
}
cout << "Values in array now: ";
for (int i = 0; i < 10; i++)
{
cout<< arr[i]<<" ";
}
int fnd;
int count = 0;
cout << "\nEnter the value to find :";
cin >> fnd;
for (int i = 0; i < 10; i++)
{
if (arr[i] == fnd)count++;
}
cout << endl;
cout <<fnd<<" was found in "<< count<<" times";
}
Comments
Leave a comment