### WRITE PROGRAMME TO SORT AN ARRAY

HELLO , EVERY ONE
I HAD EXAM SINCE WEEK AGO
AND THE QUESTION WAS ,( WRITE A PROGRAMME TO SORT AN ARRAY )
CAN ANY ONE WRITE THIS PROBLEM CORRECTLY PLEASE !!
mostafa yahia wrote:
SORT AN ARRAY

Ascending,descending,...???
Also, let's see what you did, and try to help if possible.

Thanks,
Aceix.
the nth user (who asked this kinda question)
any array not condition
i did like that it is wrong
but i will show you
that what i did
 ``123456789101112`` ``````#include "stdafx.h" #include using namespace std ; int main () { int x,y cout <<"enter the number " ; if (x>y) cout <

Hi there,

Your code doesn't do any sort of sorting at all (pun not intended), and you don't have an array.

Some info to get you started:

* You will need to create an array
* Sorting would at least involve comparing two elements of the array, as you do with x and y
* Sorting would also involve moving one of x or y to a new position in the array, this depends on the sorting algorithm you're using.

If you had an exam about sorting arrays, I expect you did at least see one or more sorting algorithms in class?

All the best,
NwN
i tried this , it is working :D

 ```#include using namespace std; void main() { int a[20]; int i,n,j,temp; cout<<"Enter the value of n:"<>n; cout<<"\nEnter the values:\n"; for(i=0;i>a[i]; } for(i=0;ia[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } cout<<"Sorted array:\n"; for(i=0;i
but, i don't think it's a fully effective program due to your objective... but, your on the right track, keep going...
thanks
if you have good idea for my programme , tell me
sorry, i didn't noticed that you're using 2 "for" loops, for iterating through the array length, and the 2nd is for iterating as long as the rest of the array. it's pretty much good program, not bad. unless, it contain some logic errors (i think). try to look at this link: http://en.wikipedia.org/wiki/Bubble_sort
Topic archived. No new replies allowed.