Answer to Question #257206 in C++ for Alex

Question #257206

Create a dynamic array of user defined size. Now take input in array from user. Take a new (integer) value from user and search that how many times the entered number is present in the array.


1
Expert's answer
2021-10-27T00:25:39-0400
#include<iostream>
#include<string>
using namespace std;






int main(){
	int size;
	int numberToSearch;
	int counter=0;
	int* numbers; 
	//Create a dynamic array of user defined size. 
	cout<<"Enter the size of the array: ";
	cin>>size;
	numbers=new int[size];
	//Now take input in array from user.
	for(int i=0;i<size;i++){
		cout<<"Enter the number "<<(i+1)<<": ";
		cin>>numbers[i];
	}
	//Take a new (integer) value from user and search that how many 
	//times the entered number is present in the array.
	cout<<"\nEnter the number to search: ";
	cin>>numberToSearch;
	for(int i=0;i<size;i++){
		if(numbers[i]==numberToSearch){
			counter++;
		}
	}
	cout<<"\n"<<counter<<" times the number "<<numberToSearch<<" is present in the array.\n\n";
	
	delete[] numbers;


	cin>>size;




	return 0;
}

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