Hello! Tell me an algorithm or a formula or a small example, how does an increasing sequence of numbers occur? For example, there are three integer pairs of unequal numbers in each of the variables a, b, c; they must be in ascending order.

2 answers 2

No sorting required. This is the entry level entry for branching. Arrays and specific languages ​​are also irrelevant - usually this is written in pseudocode. you can even have a flowchart. 3 numbers are 2 ^ 3 = 8 options. you get 3 levels of nesting conditional operators

  • Well, the man kagbe wrote the word "for example." Which suggests that he does not need to sort exactly three numbers. - Ali

In fact, the question is not entirely clear. It also depends on what language the program will be in. Many languages ​​can simply sort an array in ascending or descending order. But if you just do the sorting algorithm with your hands, you can do it like this. For example, we create an empty $massiv() array, then in the row we $massiv[a]=a numbers $massiv[a]=a , $massiv[b]=b , $massiv[c]=c and so on. And we read the array in order - this is the sorted array

  • You cannot use an array on Java. Here is a sample program: Numbers in variables: a, b, and c: 3, 9, -1. Increasing sequence: -1, 3, 9 - turtles
  • 2
    maybe I don’t understand something of course, but a high-level language without an array is nonsense. helloworld.ru/texts/comp/lang/java/java3/10-doc.htm - Grimon September
  • Just a job like that. > In the three variables a, b and c, the programmer explicitly writes three integers in pairs unequal to each other. Create a program that rearranges the numbers in variables so that when displaying a sequence of a, b and c was strictly increasing / Just how to calculate the increasing sequence. - turtles
  • Well, if you obviously only have three variables, then you can twice run a loop like this: if (a<b) then x=a,a=b,b=x; if (b<c) then x=b,b=c,c=x; if (a<b) then x=a,a=b,b=x; if (b<c) then x=b,b=c,c=x; and since there are three variables, it will be enough to get rid of these lines twice. Shift them into your own language. - Grimon
  • Thank you so much for your reply, Grimon - turtles