2021年4月10日星期六

C: why isn't the sort function changing the order of the numbers?

The sort function should change the order of the numbers scanned in from highest to lowest value. For example, if x = 6, y = 9, and z = 3, then the sort method should replace each variable: x = 9, y = 6, z = 3

//Sort function reorders parameters from highest to lowest value  int sort(int first, int second, int third) {            if (first > second && first > third) {          first = first;          if ((first > second && first < third) || (first < second && first > third)) {          first = second;            if (first < second && first < third) {               first = third;            }          }      }        if (second > first && second > third) {          second = first;          if ((second > first && second < third) || (second < first && second > third)) {             second = second;            if (second < first && second < third) {              second = third;            }          }      }          if (third > first && third > second) {          third = first;          if ((third > first && third < second) || (third < first && third > second)) {            third = second;            if (third < first && third < second) {              third = third;             }         }      }      return first;      return second;      return third;  }    int main() {      int x, y, z;      load(&x,&y,&z);      print(x,y,z);      printf("\nThe middle element is %2d", middleElement(x,y,z));      sort(x,y,z);      print(x,y,z);  }  
https://stackoverflow.com/questions/67041067/c-why-isnt-the-sort-function-changing-the-order-of-the-numbers April 11, 2021 at 11:00AM

没有评论:

发表评论