Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. int main()
  4. {
  5. int n,i;
  6. int list[100];
  7. printf("Enter Number Of Elements");
  8. scanf("%d",&n);
  9. for(i=0;i<n;i++)
  10. {
  11. scanf("%d",&list[i]);
  12. }
  13. printf("before selection sort \n");
  14. for(i=0;i<n;i++)
  15. {
  16. printf("%d",list[i]);
  17.  
  18. }
  19. int j,minIndex,minValue;
  20. for(i=0;i<n-1;i++)
  21. {
  22. minIndex=i;
  23. minValue=list[i];
  24. int flag=0;
  25. for(j=i+1;j<=n-1;j++)
  26. {
  27. if(list[j]<minValue)
  28. {
  29. flag=1;
  30. minIndex=j;
  31. minValue=list[j];
  32. }
  33.  
  34. }
  35. if(flag=1)
  36. {
  37. int temp=list[i];
  38. list[i]=list[minIndex];
  39. list[minIndex]=temp;
  40.  
  41. }
  42. }
  43. printf("After selection sort \n");
  44. for(i=0;i<n;i++)
  45. {
  46. printf("%d",list[i]);
  47.  
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement