Store more than one value in a variable with &&

Asked

Viewed 197 times

4

Can I store more than one number in a variable? For example:

m= a&&b&&c&&d&&e

I need to indicate which is the largest and smallest number that the user entered, wanted a way to do this without having to test one by one.

1 answer

5


To answer the question: it is not possible. Variable is just a name for a memory position where it fits one and only one value.

It is possible to have a variable with a set of variables, it is called array, then the contents of these variables are the elements contained within it, but the set of elements as a whole is considered a value. And each element is a variable that has only one value.

It is possible to make calculations that can transform several values into just one. Just as you can do 1 + 2 + 3 turn 6.

Usually the bit calculation is done with &, | and ~. In general it is more difficult to understand, not all cases compensate the use.

To know what to use we would need to better understand the problem. But from what you’ve informed me it seems you’ll have to compare one by one, the way to compare is that you can change.

  • It is a question of a test: Make a program that asks the user 5 numbers and indicate the largest and the smallest of them. To compare I used the format: a>b&&a>c&&a>d&&a>e.

  • 3

    @Elena it sounds like the problem XY; your question has already been answered here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.