how to sort numbers

Mar 20, 2012 at 6:37pm
a) Write a function named prime which has 1 parameter (int n). The function returns 1 if n is a prime number else 0. [done]

b) Write a program that cin>>n (n<30) and after that the user enters n numbers. Using function prime the function main must cout only the prime numbers from those entered by the user. The numbers must be sorted in increasing order.

Ex: n=7 input: 3 16 41 4 2 7 12,
output: 2 3 7 41

I know how to do this one with arrays, but do you guys know any easier, more efficient way of sorting them?
Mar 20, 2012 at 6:42pm
which way are u using to sort? and what do u mean by efficient? any sorting you do with that small an array will sort with no noticeable time.
Mar 20, 2012 at 6:55pm
I mean, is there another solution to this problem, a simple solution, besides the one using arrays?
Mar 20, 2012 at 7:11pm
well arrays are simple enough, other option is vectors but they are more complicated. if you want to push it you COULD do data structures but arrays are your simplest option.
Mar 20, 2012 at 7:18pm
... I thought vectors are the same with arrays... in this case I know how to do it with vectors ( int vector[], counter, n; cin>>n; for(counter=1;counter<=n;counter++)...
Mar 20, 2012 at 11:58pm
they are similar to arrays. just was thinking of ideas.
Topic archived. No new replies allowed.