Basic programming course: Lesson #3 Operations

in #devjr-s20w32 months ago

Assalam-o-Alaikum!!!

Greetings to my all STEEMIT members. Hopefully you all are fine and enjoying your best life on STEEMIT. I am also fine ALHAMDULILLAH. And today I will try my best to complete all tasks. And I should try to do my best as can as possible. And lets go to the tasks

image.png

Give a brief summary of what arithmetic, comparison and logical operations are for

Arithmetic, comparison, and logical operations are the basic building blocks in programming and mathematics, each serving distinct purposes:

  • Arithmetic Operations:

These are used to perform basic mathematical calculations, such as:

1. Addition (+):It will add two numbers

  • Example: 5+3=8

2.subtraction (-): It will subtract two numbers
Example: 5-3=8

3. multiplication ()It will multiply one number to another
Example:5
3=15

4.division (/): It will divide number to another

  • Example: 10/5=2

5.modulus (%) It give remainder while divide a number to an other number
Example: 22/5=2

  • Comparison operations:

Comparison operators are used to compare two values ​​and return a Boolean result (true or false).

Here are the common ones with examples:

  • Equal to(==):
    In this opertation it will check whether the number is equal

Example: 2==2 the it will return True

  • Not equal to (!=):
    In this operation it will check whther the values are not equal
    Example: 9!=7 then it will return True
  • Greater than (>):
    In this operation we will check that the value on right side is greater to the other side
    5>4, then it will show True

  • Less than (<):
    In this operation we will check that the value of right side is less then the left side
    Example: 4<5, then it will return True

  • Greater than or equal to (>=):

In this operation we will check whether the value on right side is greater or equal to the left side

Example: 5>=4, then it will return the true

  • Less than or equal to (<=):
    In this operation we will check whether the value on right side is less then or euqal to the left side
    Example: 6<=6, then it will return true

  • Logical Operators:

Logical operations are used to combine or manipulate Boolean values ​​(true or false). Here are common logical operators with examples:

They operate on numerical data to produce numerical results (eg, 5 + 3 = 8).

  • AND (&&): It Returns true if both operands are true; otherwise, it returns false.

Example:

truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse
  • OR (||): It Returns true if at least one of the operands is true; otherwise, it returns false.

Example:

truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse
  • NOT (!): Returns the opposite Boolean value. If the operand is true, it returns false, and vice versa.

Example:

truefalse
falsetrue
Make a program that asks the user for 2 numbers and evaluates if both numbers are the same.

In order to write our program, we first need to start it by declaring the variables inside it, and we'll make it clear that it will speak and its outer strings. To show, we will take the first number of the enter, in which we will take the number one, and we have to show the second number in the output, so we will write the second number of the enter. In which we will get the second number in the input and then we will apply the expression Boolean variables to it in which we have to make number one equal to number two and if number one is equal to number two. So our output will show Amen if number one is not equal to number two then our output will show if false and now I will tell you this through code and how it can be coded.

image.png

So the Output is

image.png

Transform the following mathematical expressions into arithmetic expressions on your computer:

Here is the result accoridng to this expression:

1.Y = (8 - 2) × (5 + 4)

First of all we will subtract two values whish is we subtract 8 from 2 and then we will multiply 5 and 4. then we will multiply both values which are 6 and 9. And trhe answer will be 54

Y=6*9
So Y=54

Which is greater then equal to zer0 . SO this expression is true

2.X = (8 ÷ 2) + (5 ÷ 5)
Inn this expression we will divide both value that are 8 /2.. and then will will divide 5/5.

X=4+1
X=5

Which is greater then equal to zer0 . SO this expression is true
3.Z = ((4 + 8) × 3) ÷ 2 ÷ 3

In this expression we will add two values that are 8 and 4.
4+8=12

Then we will multiply 12 to 3 , the answer will 36

And then will divide 36 by 2.
And the answer will be 18

Now, Z = ((4 + 8) × 3) ÷ 2 ÷ 3

Z= 18/ 3
=6

Which is greater then equal to zer0 . SO this expression is true

image.png

|image.png

Special thanks to @alejos7ven

Invite Friends: @josepha , @abdullahw2 , @simonnwigwe , @suboohi

Regards: @arinaz08

Sort:  
Loading...

Your post has been rewarded by the Seven Team.

Support partner witnesses

@seven.wit
@cotina
@xpilar.witness

We are the hope!