No code is needed, only simple math theory.
Like:
- print “enter your age”
- read(age)
- if age>20
- result=”adult”
- print”you are”
- print(result)
I am going to attend C language classes but before that I want to learn some basics.
I need a program/algo that finds maximum and minimum of three numbers using multiple-if or nested-if.
There’s the straightforward way:
There’s the way with the minimum number of comparisons:
There’s the way with the fewest lines of code, thanks to the ternary operator:
There’s the way twalberg mentioned in the comments:
max can be defined in all of these ways too, replacing
<with>. You can also define it in terms ofmin:If you don’t wish to learn how to declare functions yet, you can drop some of these straight into your main function. For example, the second method: