Write a program that looks at a 1D array of 9 numbers and verifies that the array contains each of the
numbers 1-9 exactly once.
It should display a message "Valid Array!" if the array meets the requirement.
Otherwise, your program should let the user know what is wrong with the array.
(Does it contain a number out of the range? Is a number not found in the array? Is a number duplicated?)
#include <iostream>
using namespace std;
int main ()
int number;
int array[8] {1,2,3,4,5,6,7,8,9} ;
{
cout<<"Enter a number in the range 1-9:\n";
cin>>number
while (number < 1 || number > 9)
#include <iostream>
usingnamespace std;
int main ()
{
int number = 0;
int array[10]{};
while
(
cout << "Enter a number in the range 1-9 ( -1 to end ): " &&
cin >> number &&
number != -1
)
{
if(number > 0 && number < 10)
array[number]++;
else
cout << number << " wrong!\n";
}
for(int i = 1; i < 10; ++i)
cout << i << " occurred " << array[i] << " times.\n";
return 0;
}