Answer to Question #339476 in C++ for kamali john

Question #339476

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


1
Expert's answer
2022-05-10T16:00:38-0400
#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;
	}
	
}

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