Advertisement
Sanlover

Untitled

Dec 22nd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int N;
  5. cout << "Enter the size of arrays = ";
  6. cin >> N;
  7.  
  8. int* a = new int[N];
  9. int* b = new int[N];
  10.  
  11. cout << endl << "Fill the array:" << endl;
  12. for (int i = 0; i < N; i++) {
  13. cout << i + 1 << ") ";
  14. cin >> a[i];
  15. }
  16.  
  17. int pos = 0;
  18. for (int i = 0; i < N; i++) {
  19. if (a[i] > 0) {
  20. b[pos] = a[i];
  21. pos++;
  22. }
  23. }
  24. cout << endl << "Array B:" << endl;
  25. for (int i = 0; i < pos; i++) {
  26. cout << i + 1 << ") " << b[i] << endl;
  27. }
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement