Write a function
void switchEnds(int *array, int size);
that is passed the address of the beginning of an array and the size of the array. The function swaps the values in the first and last entries of the array.
Here is the code to switch two integers:
void exchange(int *p, int *q)
{
int temp = *p;
*p = *q;
*q = temp;
}
Demonstrate the function with a driver program.
Here is my code so far, I am stuck.
#include<iostream>
#include<iomanip>
using namespace std;
// Function prototype
void switchEnds(int *, int *);
int main()
{
// define array
const int TEMPS = 5;
int temp[TEMPS];
temp[0] = 32;
temp[1] = 36;
temp[2] = 40;
temp[3] = 45;
temp[4] = 54;
switchEnds(temp, TEMPS);
cout << "Calling the switchEnds function:" << temp[TEMPS] << endl;
system("Pause");
return 0;
}
// Function switchEnds is to switch values in the first and last array entries
void switchEnds(int *p, int *q)
{
int temp = *p;
*p = *q;
*q = temp;
}

New Topic/Question
Reply




MultiQuote







|