Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //function prototype
  5. void moveAndSortInt(int[], int);
  6. int main() {
  7. displayInfo();
  8. cout << "\n";
  9. int ary1[] = { -15, 450, 6, -9, 9 };
  10. int ary2[] = { 100, -15, 450, 6, -91, 9 };
  11. int size, i(0);
  12. size = 5;
  13. cout << "Original ary1[]\n";
  14. for (i = 0; i < size; i++) {
  15. cout << ary1[i] << " ";
  16. }
  17. cout << endl;
  18. cout << endl;
  19. moveAndSortInt(ary1, size);
  20. cout << "Calling moveAndSortInt() - -\n";
  21. cout << endl;
  22. cout << "Updated ary1[]\n";
  23. for (i = 0; i < size; i++) {
  24. cout << ary1[i] << " ";
  25. }
  26. cout << endl;
  27. cout << endl;
  28. size = 6;
  29. cout << "Original ary2[]\n";
  30. for (i = 0; i < size; i++) {
  31. cout << ary2[i] << " ";
  32. }
  33. cout << endl;
  34. cout << endl;
  35. moveAndSortInt(ary2, size);
  36. cout << "Calling moveAndSortInt() - -\n";
  37. cout << endl;
  38. cout << "Updated ary2[]\n";
  39. for (i = 0; i < size; i++) {
  40. cout << ary2[i] << " ";
  41. }
  42. cout << endl;
  43. cout << endl;
  44.  
  45. system("pause");
  46. }
  47. // Fuction definition
  48.  
  49. void moveAndSortInt(int ary[], int size) {
  50. int i, j, temp;
  51.  
  52. for (i = 0; i < size; i++) {
  53. if (ary[i] % 2 == 0) {
  54. for (j = size - 1; j > 0; j--) {
  55. if (ary[j] % 2 != 0) {
  56. temp = ary[i];
  57. ary[i] = ary[j];
  58. ary[j] = temp;
  59.  
  60. j = 0;
  61. }
  62. }
  63. }
  64. }
  65. return;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement