fork download
  1. #include<iostream>
  2. using namespace std;
  3. int findSmallest (int[],int);
  4. int main ()
  5. {
  6. int myarray[10] = {11,5,2,20,42,53,23,34,101,22};
  7. int pos,temp,pass=0;
  8. for(int i=0;i<10;i++)
  9. {
  10. cout<<myarray[i]<<"\t";
  11. }
  12. for(int i=0;i<10;i++)
  13. {
  14. pos = findSmallest (myarray,i);
  15. temp = myarray[i];
  16. myarray[i]=myarray[pos];
  17. myarray[pos] = temp;
  18. pass++;
  19. }
  20. for(int i=0;i<10;i++)
  21. {
  22. cout<<"\n"<<myarray[i]<<"\t";
  23. }
  24. cout<<"\n"<<pass;
  25. return 0;
  26. }
  27. int findSmallest(int myarray[],int i)
  28. {
  29. int ele_small,position,j;
  30. ele_small = myarray[i];
  31. position = i;
  32. for(j=i+1;j<10;j++)
  33. {
  34. if(myarray[j]<ele_small)
  35. {
  36. ele_small = myarray[j];
  37. position=j;
  38. }
  39. }
  40. return position;
  41. }
Success #stdin #stdout 0.01s 5652KB
stdin
Standard input is empty
stdout
11	5	2	20	42	53	23	34	101	22	
2	
5	
11	
20	
22	
23	
34	
42	
53	
101	
10