Advertisement
_takumi

lizing

Oct 18th, 2022
1,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. // use local variables
  4. // use functions
  5.  
  6. int solve(int *a, int *b, int n, int x) {
  7.     int j = 0;
  8.     for (int i = 0; i < n; ++i) {
  9.         if (a[i] % x == 0) {
  10.             b[j++] = a[i];
  11.         }
  12.     }
  13.     return j;
  14. }
  15.  
  16. int main() {
  17.     int n, x;
  18.     int *a, *b;
  19.     scanf("%d%d", &n, &x);
  20.     a = (int *)malloc(n * sizeof(int));
  21.     b = (int *)malloc(n * sizeof(int));
  22.     for (int i = 0; i < n; ++i) {
  23.         scanf("%d", &a[i]);
  24.     }
  25.     int sz = solve(a, b, n, x);
  26.     for (int i = 0; i < sz; ++i) {
  27.         printf("%d ", b[i]);
  28.     }
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement