Tuesday 15 February 2011

c++ : help to correct exercise with array and function -



c++ : help to correct exercise with array and function -

**define function given array of x elements contents modified contain same elements in reverse order. think thought good: using temp var in function create exchange. problem source... thanks... **

#include <iostream> using namespace std; const int length=5; void exch(arr_exch[]){ int s,e,tmp; s=0; f=length; while (e-s!=1){ tmp=arr_exch[s]; arr_exch[s]=arr_exch[e]; arr_exch[e]=tmp; } cout << arr_exch; } int main() { int arr[length],counter; cout << "enter 5 integers:\n"; cin >> arr[0]; (counter=0; counter<length; counter++){ cin >> arr[counter]}; void exch (arr[length]); homecoming 0; }

since want contents don't have create other array or variable. create loop this:

for(int = length -1; >= 0; i--){ cout << arr[i] << endl; }

c++ arrays function

No comments:

Post a Comment