Answer to Question #258076 in C++ for anu

Question #258076

Given an array A of N integers and two integers X and Y, find the number of integers in the array that are both less than or equal to X and divisible by Y.


1
Expert's answer
2021-10-28T06:05:11-0400
#include<iostream>
#include<string>
using namespace std;






int main(){
	int size;
	int X;
	int Y;
	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];
	}
	cout<<"Enter X: ";
	cin>>X;
	cout<<"Enter Y: ";
	cin>>Y;
	for (int i = 0; i < size; i++) {
		if (numbers[i] <= X && numbers[i] % Y == 0) {
			counter++;
		}
	}


	cout<<"The number of integers in the array that are both less than or equal to X and divisible by Y: "<<counter<<"\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