Support Forums

Full Version: Array Help[C++]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
can any one help me write a program that sorts and displays elements of a one

dimensional integer array both in ascending and descending orders, where the

elements of the array are to be entered from the keyboard.

let the size of the array be 5.
Guess that N = is the dimmension of the array.

Code:
for(int j =0; j<N; j++) {
for(int i=1; i<N; i++) {
if(array[i]>array[i-1]) {
int tmp = array[i];
array[i] = array[i-1];
array[i-1]=tmp;
}
}
}

It will sort from the biggest element to smallest, for inversely just change the sign to "+" at the start of if circle.

I hope I help it to solve your problem.
exce.......good