Please help writing a with arrays, 20 numbers read forwards and backwards

Im trying to write a program that holds an array of 20 numbers read
in from the keyboard and display them backwards.

this is what i have:

#include <iostream>
using namespace std;

void invertArray(char[], int);

int main()
{
char num [52] = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20";

cout << num << endl;
invertArray(num, 50);
cout << num << endl;
system("pause");
return 0;
}

void invertArray(char arr[], int count)
{
int temp;
for (int i = 0; i < count / 2; ++i)
{
temp = arr[i];
arr[i] = arr[count - i - 1];
arr[count - i - 1] = temp;
}
}

It works but i have a feeling im not doing the assignment right..
Last edited on
Topic archived. No new replies allowed.