#include <iostream> int main() { int L, N, M; int count = 0; std::cout << "Enter values for L, N, and M: "; std::cin >> L >> N >> M; for (int i = L; i <= N; i++) { if (i % M == 0) { count++; } } std::cout << "Number of elements divisible by " << M << " in the range from " << L << " to " << N << ": " << count << std::endl; return 0; }
Пример работы программы:
Enter values for L, N, and M: 3 15 5 Number of elements divisible by 5 in the range from 3 to 15: 3
int main() {
int L, N, M;
int count = 0;
std::cout << "Enter values for L, N, and M: ";
std::cin >> L >> N >> M;
for (int i = L; i <= N; i++) {
if (i % M == 0) {
count++;
}
}
std::cout << "Number of elements divisible by " << M << " in the range from " << L << " to " << N << ": " << count << std::endl;
return 0;
}
Пример работы программы:
Enter values for L, N, and M: 3 15 5Number of elements divisible by 5 in the range from 3 to 15: 3