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.
#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;
}
Comments
Leave a comment