0

what is an algorithm for a program that reads 4 integers (not in array) and print them without using loop

Edited by deceptikon: Moved to computer science

5
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by jllany.anthony
0

Well, you could use if-else if-else statements, but it will be a very long & messy code because of the permutation of the value in each variable.

0

It depends on your definition of loop. For example, if you create a detached recordset and read the integer values into it, you could then use the Sort method to rearrange the values. Your program would use no loops (as long as you brute-forced the input), however, the Sort method would undoubtedly have a loop hidden inside. Same thing with using QuickSort.

Although, strictly speaking, your problem definition does not mention sorting (only the thread title does). Your actual problem definition says you only have to read and write the numbers.

Edited by Reverend Jim

0

Psuedo codeish:

Get four numbers: a, b, c, d
if a is greater than b, swap a and b
if b is greater than c, swap b and c
if c is greater than d, swap c and d
if a is greater than b, swap a and b
if b is greater than c, swap b and c
if a is greater than b, swap a and b

Not very complicated.

0

Is it possible to do it without swapping numbers? Because our teacher has asked us to do without it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.