Advertisement
Lisaveta777

C_tasks 5.28 sort by choise

Dec 17th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #define SIZE 10
  3.  
  4. //sort by choice:find smallest on first iteration, put it into index 0, second - index 1...
  5.  
  6. int main()
  7. {
  8.     int place,temp,i,j,k,arr[SIZE]={9,5,7,3,2,6,8,4,1,0};
  9.     for(i=0;i<SIZE;i++)printf("%d\t",arr[i]);//print array
  10.  
  11.     for(i=0;i<SIZE-1;i++)//place to put max number
  12.     {printf("\ni=%d\n",i);place=SIZE-i;
  13.         for(j=i+1;j<SIZE;j++)
  14.         {printf("j=%d\t",j);
  15.             if(arr[i]>arr[j])
  16.             temp=arr[i],arr[i]=arr[j],arr[j]=temp;
  17.         }//for j
  18.  
  19.         printf("\n");
  20.         for(k=0;k<SIZE;k++)printf("%d\t",arr[k]);//print array'
  21.         printf("\n");
  22.         if(i==SIZE-2)i=SIZE;
  23.     }//for i
  24.     for(i=0;i<SIZE;i++)printf("%d\t",arr[i]);//print array
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement