Gargit

Functions Exercise Part 14

Aug 13th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int Split(int array_input[], int arraySize, int firstOutputArray[], int secondOutputArray[])
  4. {
  5.     int positiveHits = 0;
  6.     for (int i = 0; i < arraySize; i++)
  7.     {
  8.         if (array_input[i] >= 0)
  9.         {
  10.             firstOutputArray[i] = array_input[i];
  11.             positiveHits++;
  12.         }
  13.         else
  14.         {
  15.             secondOutputArray[i] = array_input[i];
  16.         }
  17.     }
  18.  
  19.     return positiveHits;
  20. }
  21.  
  22. int main()
  23. {
  24.     int input_array[5] = { -2, 4, 6, 8, -10 };
  25.     int first_output_array[5], second_output_array[5];
  26.    
  27.     int result = Split(input_array, 5, first_output_array, second_output_array);
  28.  
  29.     std::cout << "Number of positive integers in array: " << result << std::endl;
  30.  
  31.     system("pause");
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment