dipf

Untitled

Nov 24th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. int i, temp, swapped;
  7. int howMany = 10;
  8. int goals[howMany];
  9.  
  10.  
  11. for(i=0; i<howMany; i++){
  12. goals[i] = ( rand()%25 )+1;
  13. }
  14.  
  15. printf("Orginal List \n");
  16. for(i=0; i<howMany; i++){
  17. printf("%d \n", goals[i]);
  18. }
  19.  
  20. while(1){
  21. swapped = 0;
  22.  
  23. for(i=0; i<howMany-1; i++){
  24.  
  25. if(goals[i]>goals[i+1]){
  26. int temp = goals[i];
  27. goals[i] = goals[i+1];
  28. goals[i+1] = temp;
  29. swapped = 1;
  30. }
  31. }
  32.  
  33. if(swapped==0){
  34. break;
  35. }
  36. }
  37.  
  38. printf("\nSorted List\n");
  39.  
  40. for(i=0; i<howMany; i++){
  41. printf("%d \n", goals[i]);
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment