| shabby (1) | |
|
#include<iostream.h> void sort(int A[20],int N) { int i,j, temp; for (i=0;i<N;i++) { for(j=i+1;j<N;j++) { if(A[i]>A[j]) { temp=A[i]; A[i]=A[j]; A[j]=temp; } cout<<A[i-1]; } } void main() int A[20], i, j, N; cout<<"enter no. of elements"; cin>>N; cout<<"enter array"; for(i=0;i<N;i++) { cin>>A[i]; sort(A[20], N); } | |
|
Last edited on
|
|
| Marcan (24) | |||||
|
Well, I don't think anyone would want to rewrite the code for you... But here's a couple of pointers: 1-It isn't standard anymore for main to return void. Return an int instead.
2-iostream.h is a deprecated header. use <iostream> instead (you should probably change your IDE) 3-Your code is all wrong. Right after your void main() (remember to use int main) there should a { immediately following it. 4-Use the code tags here in the forum to post code, just like so:
| |||||
|
|
|||||
| TheIdeasMan (1753) | |
| It would also be helpful if you posted compiler errors. | |
|
|
|
| Longazan (22) | |||||
Maybe it is because of my incompetence but I have never seen a function that has an array as a parameter be declared the way you did. I mostly see something like this
And when call the function only the name of the array is pass in
| |||||
|
|
|||||
| usandfriends (186) | ||||||
Okay, I made your code compilable, but that doesn't mean it works as it should. 1. Line 5: You call an array with 20 values in it, but then you ask for the N value. If I put in any value above 20, your program will throw away the last N-20 values. I suggest you wait until the user enters a N value, then call an array[N];.2. Line 25: You are showing users the values already, so the output gets all messed up. 3. Everywhere: Your program is not very user friendly. Format your questions and comments so your program looks elegant. Example: instead of std::cout<<"enter array";, you should put std::cout<<"Enter array item "<<i<<": ";. In this case, the user knows how many items he/she has entered and it looks clean and correct.Now, take a look at my code, which I made just a few days ago:
Use this only as an example (1. It is extensive. 2. It uses up quite some memory). Although my code is longer, a sample run shows its user-friendliness:
It is good to tell your user what the program does. Then, prompt the user in a friendly way. Give them information so they can understand it. Also, the other are right about forum posting: include code tags and other formatting optWell, that's all! Good luck and happy coding! ~Usandfriends | ||||||
|
Last edited on
|
||||||