Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array Help[C++]
#1
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.
Reply
#2
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.
Reply
#3
exce.......good

[Image: ubuntu_5.11.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  2D Array Editor. InfamousKnight 0 541 03-11-2011, 07:11 PM
Last Post: InfamousKnight
  Something absurdly wrong with char array J4P4NM4N 2 806 11-29-2009, 04:36 PM
Last Post: J4P4NM4N

Forum Jump:


Users browsing this thread: 2 Guest(s)