Linux - Arithmetic operators
13K views
Nov 28, 2024
Linux - Arithmetic operators
View Video Transcript
0:00
Now in this video I'm going to explore your arithneten
0:04
Arithmetic operators into our previous video it contains all the particular operators or we can say a
0:10
symbols we use for adding subtraction and using into arithematical operations The same symbols we are going to use here the very first I can see here that is your plus
0:21
plus means additional symbol this can be used for adding two different variables
0:26
same way we can use the subtraction the subtraction operator can be used for
0:32
subtracting the one variable with the other variable same way you can use the
0:37
multiplication so multiplication will be used in such a way if I want to
0:41
multiply one variable with the other variable then we have a division division
0:47
division can be used for dividing the other variable or the second variable with the
0:52
first or the first variable with the second variable just you need to define a
0:56
or use the slash that is front slash then you have module module can be used for with the
1:03
right hand operators with the left hand operators and set a reminder we can say we are
1:08
dividing one variable with the second variable but we also want a divider or the return
1:16
remainder then we have equals to sign equals to sign can be used if I want to left
1:23
the operant by dividing my two different variables. So you can see you have a equals to dollar
1:31
B would assign the value of B into a so that we get the operant. Then we have equals to equals to
1:39
if I use this two equal to at the time when I want to compare two different variables like if I
1:46
want to compare a with B whether they are equal or not. Same way we can use not equal
1:53
that is exclamation equals to that if i want to check whether my this variable is same or not with that
2:01
variable so here i'm defining a condition this variable is not equal to the other variable so we can
2:08
add any of the result to it so we can create the programs by using this arithematical operators so let us
2:16
check into our terminal how we can create a script file or how we can create a program using some of this
2:23
this operators. So here we are starting with your arithmetical operators. So I'll create a file
2:35
color dot as such. Okay so I'm going to you know enter some of the numbers or I'm going to fetch the data
2:43
or the numbers from the user. So for that again I'll give some
2:47
instruction to my user and enter the first number and the user will enter the first number here Once he has entered the number we should read the value he has entered
3:07
or we can enter the number and I'll take the variable as A
3:12
and then go enter the second number. So I have also got the second number which I'm going to store in a variable B
3:34
So once you have done that, now I want that this two A and B should be added
3:39
So I'll give echo addition of the above two numbers are, sorry, is
3:53
sorry is I can just define in such a way that you need to use your ascent you know
4:05
bar that is your under the title symbol you have so TILD will contain that
4:11
as an ascent bar that is called as an grave as well so this you will be using
4:16
post that you need to give the space a single space you'll specify and will
4:20
give the expression and then you will call the first variable again space addition sign again dollar be the second variable
4:31
and again you are going to use the as in grave symbol once you have done with that
4:37
just save it and move out of it and just run it and check whether you are able to
4:41
run the same so first number I'm going to enter two and then three okay so there is a
4:53
I'll just check. Okay, so I haven't replaced this quotes
5:07
So for this I'll come here and just I'll just as such
5:18
arithematical dot as such first number is 2, number number is 3
5:23
and an addition of both the numbers is 5 right same way we can add much of the calculations into the same file itself
5:31
by taking the same variables we have added okay so 2 5 we can see it is 7
5:38
now I'm just going to add some more instructions to it so that it can multiply, it can divide the two numbers
5:47
So for that, again, I'll give, I'll come at home, sorry your end and I going to add it the other numbers echo the difference between the two numbers the above numbers that we need to check with the
6:23
the ascent core of symbol EXPR space here again we have space now I will give
6:32
this abstraction sign and then sorry your first variable I'll call then
6:38
extraction sign and then the other variable again ascent Corave Cipol okay so again the mistake I did is I need to again
6:53
and the quotes. Once you have done with that, you can check we're using the arithmetical
7:00
as such. First number, for example, I'm adding 5. Second number I'm going to add this 2
7:06
So this is the 7 and the difference between these two numbers is 3. Same way we can add more of it
7:14
So I'm going to right now I'm going to add everything into it like multiplication, division
7:18
So for that again I'll move into the arithematical as such. And again I'll come at the end and I'm going to go on the second line
7:30
And on second line I'm going to add multiplication of both the above numbers
7:45
So, EXPR, again, I will give space EXPR
7:56
dollar A, and again, for multiplication, I'll use the backslash and a strict, and then dollar B
8:07
Again, space, as in graph symbol, and end the quotation. Same way, I can also divide both
8:15
the numbers we can say division generally to show you the remainder of both the numbers
8:45
A XPR, dollar A. For divide we will be using front slash and then dollar B Done with it and then quotation just I save this sorry we save this
9:07
and we'll just run the file and find first number I'm going to define for
9:12
number two and this is the not the remainder sorry I'll this is the who shouldn't
9:21
we generally get so this is what exactly we have so we have a also calculate it, we have added both the numbers, we have, you know, set the difference between
9:30
two numbers, multiplication of the snow number, and the division of value of this particular
9:35
two numbers we have defined here. So this is how generally we can calculate by using the different
9:41
arithematical operators. Even we can use your, you know, different operators like your relational
9:49
operators, we have seen too, where relational operators are like for, if I want to check
9:54
whether these both the values are equal or not. So, into a rhythmatical, for example, I'm using the same one
10:05
So I want to compare whether this value dollar A is equals to equals to dollar B or not
10:14
But here what will happen, even though if I have added this value, this value, if it is true, it's okay
10:20
If it is false, so I won't get any, no. message. Now for example I'm going to add here both are
10:29
both are equal values okay and then I'm going to save it
10:46
Once we save it will again run the same file or a thematical dot as such I'm going to
10:52
add to again too. Okay so there was an error into the same. We can do is we haven't
11:04
defined the echo that's the reason it is taking it as in comment. Okay that's
11:10
that. Save it again I'm going to run the same as such or arithmetical dot as
11:17
such enter both the values so it is showing you what the values are equal that is
11:24
equating but it is not based on the condition right if I want to be to make it
11:30
based on the condition I have to mention some conditions so for that we will be
11:35
using the if conditions so other operators like your boleyn operators checking the
11:40
file test operators all this will be able to see in the volume operators and
11:44
and while we are defining the, no, if or loops commands. So how to form a loop, how to make the decisions according to the conditions that we are going to see into the next videos
#Computers & Electronics
#Programming
#Software