write a c++ program that initializez 20 elements the program will ask the user to enter a number checks if it is an element in array
#include <iostream>
using namespace std;
int main()
{
int arr[20] = {1,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57};
int number, count = 0;
while (number != 999){
count = 0;
cout << "Enter number (999 - exit): ";
cin >> number;
for (int i = 0; i < 20; i++){
if (number == arr[i])
count++;
}
if (number == 999)
continue;
if (count > 0){
cout << "Number " << number << " belongs to the archive!" << endl;
}else
cout << "Number " << number << " does not belong to the archive!" << endl;
}
}
Comments
Leave a comment