C   31
decision tree c
Guest on 17th September 2023 09:31:55 PM


  1. // decision tree c
  2.  
  3. #include <stdio.h>
  4.  
  5.  
  6. int main()
  7. {
  8.    int n1, n2, n3;
  9.  
  10.    printf("sort 3 numbers in descending order\n");
  11.    printf("input numbers = ");
  12.    scanf("%d%d%d",&n1,&n2,&n3);
  13.    
  14.    printf("numbers in descending order = ");
  15.    
  16.    // THE decision tree
  17.    
  18.    if (n2 > n1)
  19.       if (n3 > n2)
  20.          printf("%d %d %d\n",n3,n2,n1);
  21.       else if (n3 > n1)  
  22.               printf("%d %d %d\n",n2,n3,n1);
  23.            else printf("%d %d %d\n",n2,n1,n3);
  24.    else      
  25.       if (n3 > n2)
  26.          if (n3 >  n1)
  27.              printf("%d %d %d\n",n3,n1,n2);        
  28.           else printf("%d %d %d\n",n1,n3,n2);
  29.       else printf("%d %d %d\n",n1,n2,n3);  
  30.    return 0;
  31. }

Raw Paste

Login or Register to edit or fork this paste. It's free.