An array of N natural numbers is given. Indicate those numbers, the remainder of which division by M is equal to L (0 ≤ L ≤ M-1).

#include "stdafx.h" #include <iostream> #include <math.h> #include <stdio.h> #include <cstdlib> #include <locale.h> using namespace std; int main() { int n=15, k=0, i,m1, m, l; int b[15],A[15]; k=0; m1=0; cout<<"vvedite m и l"; cin>>m; cin>>l; for (i = 0; i < n; i++) { cout << "A[" << i << "] = "; cin >> A[i]; } for (i = 0; i < n; i++) { l=A[i]%m; if ((0<=l)&&(l<=(m-1))) { b[k]=i; cout <<"b["<<k<<"]="<<b[k]<<endl; k++; } } system("pause"); return 0; } 
  • 3
    What is the question then? - Denis
  • The question does not contain a question) - Isaev

2 answers 2

 l=A[i]%m; if ((0<=l)&&(l<=(m-1))) 
 if (A[i] % m == l) 
  • And for what a minus? - Qwertiy
  • it's not me. I can not yet - Sergei Koshelev
 for (i = 0; i < n; i++) { if (l == A[i]%m); cout << A[i] <<endl; } 

The remainder of the division by M will always be in the range of 0 to M-1 . By the way, it probably makes sense to check when entering l and m that 0 ≤ L ≤ M-1 ...