Answer to Question #336600 in C++ for kiri

Question #336600

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
2022-05-02T14:45:29-0400
#include <iostream>
using namespace std;




int main() {
    int i, n, x, y, count = 0;
    cout << "Enter n: ";
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++){
		cout << "Enter " << i << " element: ";
		cin >> a[i];     	
	}
    cout << "Enter X: ";
    cin >> x;
	cout << "Enter Y: ";
	cin >> y;
	for (i = 0; i < n; i++){
		if ((a[i] <= x) && (a[i] % y == 0)){
			cout << a[i] << endl;
			count ++;
		}
	}
	cout << "\n**************************";
    cout << "\n*       RESULT : " << count <<  "       *";
    cout << "\n**************************";
    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