Support Forums
Array Help[C++] - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20)
+---- Thread: Array Help[C++] (/showthread.php?tid=3489)



Array Help[C++] - se7en - 12-10-2009

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.


RE: Array Help[C++] - geeK - 12-10-2009

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.


RE: Array Help[C++] - Sagittarius - 12-11-2009

exce.......good