Advertisement
aunkang

Sort

Jan 8th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2.   void sort();
  3.   int main()
  4. {
  5.     int num[3],temp;
  6.     char word[4];
  7.     scanf("%d %d %d",&num[0],&num[1],&num[2]);
  8.     scanf("%s",word);
  9.     sort(num[0],num[1],num[2]);
  10.     if(word[0] == 'A' && word[1] == 'C')
  11.     {
  12.         temp = num[1];
  13.         num[1] = num[2];
  14.         num[2] = temp;
  15.     }
  16.     else if(word[0] == 'B' && word[1] == 'A')
  17.     {
  18.         temp = num[0];
  19.         num[0] = num[1];
  20.         num[1] = temp;
  21.     }
  22.     else if(word[0] == 'B' && word[1] == 'C')
  23.     {
  24.         temp = num[0];
  25.         num[0] = num[2];
  26.         num[2] = num[1];
  27.         num[1] = temp;
  28.     }
  29.     else if(word[0] == 'C' && word[1] == 'A')
  30.     {
  31.         temp = num[0];
  32.         num[0] = num[1];
  33.         num[1] = num[2];
  34.         num[2] = temp;
  35.     }
  36.     else if(word[0] == 'C' && word[1] == 'B')
  37.     {
  38.         temp = num[0];
  39.         num[0] = num[2];
  40.         num[2] = temp;
  41.     }
  42.     printf("%d %d %d",num[1],num[1],num[2]);
  43.    
  44.    
  45.     void sort(num[0],num[1],num[2]);
  46.     {
  47.         int i,j,temp;
  48.         for(i=0;i<=1;i++)
  49.         {
  50.             for(j=0;j<=1;j++)
  51.             {
  52.                 if(num[j]>num[j+1])
  53.                 {
  54.                     temp = num[j];
  55.                     num[j] = num[j+1];
  56.                     num[j+1] = temp;
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     return 0;  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement