Basic Programming Course: Lesson #3; Operations
Hello friends and welcome to my article in the SEC S20/W3 in this great dynamic I would be sharing my thoughts immediately.
This is used for basic calculations such as addition +
subtraction -
division /
multiplication *
and other expressions which include exponentiation ^
amidst others. It is basically used to incompetent these mathematical parameters to program.
- Addition: To sum two or more values we use
+
In a scenario in which I have to add up the values 8 and 6 it would be displayed in a program format below thus:
- Subtraction: To interprete this
-
we remove one value from another. Scenario in this case we use the same variables 8 minus 6 in cases where two values are to be removed from each other as shown below thus:
Multiplication: We must multiply two values using the special command
*
This is what we use. If we want to multiply 12 by 412*4=48
Division: To perform division, we have to be the division sign
/
If we want to divide two numerical values say8/4= 2
- Module: This is usually the remainder after the division has taken place. It could be a whole number, fraction or decimal. For instance if 9 divided by 2 it would be 4 remainder ½ or 0.5. I would be using
%
to operate during the division process.
For comparison operation to take place two or more variables must be put in place. Which would return a true or false (Boolean result). Examples of these comparison operative would be explained below thus;
Greater Than (>):
This is the operator sign that tells us the greater value between two numerical values. Scenario; 10 is greater than 2 the result would be 10>2
Less Than (<):
This is the opposite of greater than, it is a basic operator command which is used in comparison of two variables. Scenario; say between 20 and 10 it would be placed that 10<20
as a function of the less than command.
This is used to compare two or more variables at the same time. In other words they enable you create more complex conditional statement which principally affects decision making. The are Boolean expressions used to compare while enhancing decision making. Key facts of the logic operators entails the use of AND, OR If a conditional structure its true and meets all conditions it is false
AND(&&): When both conditions are true it's obvious that we use AND. Picture a girl is fair and tall, the expression would be true because she meets the conditions stated in the scene.
Print "Does user meet both condition? Is_fair and is_tall;
OR(||): If we have two condition, a conditional statement in which a subject does meet some of the complete prerequisite in the statement it is true. But in situation where it nulled all prerequisite in statement it is false.
Print "Does the user meet at least one condition? is_fair or is_tall;
I would be performing this task on my online IDE a pictographic representation of the task so all can see.
coded program | result |
---|
• First expression "Y"
Y = (8-2)*(5+4)
• Simplification: (8-2)* (5+4)= 6 * 9 = 54
• So Y = 54
Subsequent expression "x"
x= (8/2) + (5/5)
• Simplification: (8/2)+ (5/5)= 4+1 = 5
• So x = 5
• Subsequent expression "z"
z = ((4+8)*3) / (2 * 3)
• Simplification ((4+8)*3) / (2 * 3) =
(12 * 3)/6= 36/6 = 6
• So z = 6
all_positive= (x>=0) and (Y>=0) and (z>=0)
Print (F " are x,y,z all greater than or equal to 0? {all_positive})
End Algorithm
coded program
Cc; |
---|