0:00
so far we have seen comparison operators
0:03
like less than equal to less than or
0:07
equal to and so on will see a bunch of a
0:11
few more operators in this session
0:14
ok so let us consider the model operator
0:18
which we have already seen in when we
0:20
discussed your pins gcb so a the same
0:23
percentage be gives the remainder when
0:27
is / be okay so suppose we have the
0:31
following problem we get a number a and
0:35
we want to check whether the given
0:36
number is divisible by 6 if it is
0:39
divisible by 6 a model 06 will be 0 but
0:44
the remainder will be 30 so we write a
0:47
simple code you have int a SF type int
0:53
then scan the number using scanning
0:57
percentage D and E and then you test
1:00
whether is divisible by 6 to testify
1:05
that is divisible by 6 you check with a
1:07
name or 60 if it is divisible you say
1:12
that input is divisible by 6 persons de
1:15
que a device else print of the input is
1:22
ok very simple operation now let's make
1:28
it slightly more elaborate suppose you
1:31
have to test whether this is lightweight
1:34
supposed to have to test whether a given
1:36
number isn't is divisible by 6 and x 42
1:42
numbers okay how do you do this so you
1:47
scan of the number and your test where
1:49
that is divisible by 6 so a model 06 is
1:53
0 if that is true then you also check
1:58
that there a model of 40
2:02
ok if both are true then you print that
2:06
the given number is divisible by 6 and
2:10
so person is divisible by 6 and 4 so you
2:14
can argue about this program and see
2:16
that if it is divisible by 6 but not by
2:20
4 then it will enter the first if but
2:24
not enter the second if therefore it
2:27
will not print that accessible by six in
2:30
similarly if it is not even divisible by
2:32
6 it will not even enter the first if
2:35
condition so you'll in any case not
2:38
print that is visible so convince
2:40
yourself that this particular code will
2:44
print a number is divisible by 6 and
2:47
four if and only live the given number
2:52
is divisible by both six and four
2:55
ok now that that piece of code was
2:59
slightly long is there any way to write
3:03
the same code with a fewer number of
3:06
ok and for this sea provides what what
3:09
are known as logical operators now that
3:12
the logical operators in boolean logic
3:16
which are boolean and boolean or and
3:20
boolean not okay so there are three
3:22
logical operations and are not and see
3:26
provides all of them so the same if
3:30
condition that we wrote before you could
3:32
have easily said if it is disabled by
3:35
six and if it is divisible by 4 then
3:40
alright so for this sea provides and
3:45
operated which is the boolean and
3:53
the boolean and operation in c is given
3:56
by two amps looking so by now you should
4:02
be familiar with the fact that boo
4:04
certain operations in the NC have
4:08
repeated characters for example we
4:11
already have seen the Equality operation
4:13
which was equal equal
4:14
similarly the boolean operation and it
4:17
is actually the and simple on the
4:19
keyboard but you have to have two of
4:21
them that represents the logical and so
4:25
this expression says if a model 6 is 0
4:30
so this expression is what this for is a
4:35
multiple of six days to a summer
4:38
multiple of 6 and this is the expression
4:40
which test whether it is a multiple of 4
4:47
ok so if both conditions are true then
4:50
you say that that given number is
4:52
divisible by 6 and before
4:54
ok so constitutive and percent signs
5:01
that is the and symbols without any
5:03
blanks in between is to see operator
5:05
corresponding to the mathematical and
5:08
logical and function
5:10
ok so it takes to where losers input and
5:14
returns 0 if any of the values isuzu if
5:18
both values are 1 then it returns
5:21
ok so this is the same as the logical
5:23
end if either of them is 0 then the
5:27
result is 0 if both of them are one then
5:30
the result is one so the truth table for
5:36
the operation and is as follows if is a
5:40
nonzero value and beasts a nonzero value
5:42
then see considers that motor through so
5:47
the output values of a and b is 1 if is
5:53
0 and b is any value at all the output
5:56
s20 ok and b is not evaluated
6:01
so this is the same as the logical and
6:04
the only two thing to notice that if if
6:09
in evaluating a and B you already know
6:12
that a zero then you know the result is
6:14
ok so see will not bother to evaluate be
6:17
because it knows that result is already
6:19
sooo ok every expression has a type a
6:26
and B is of type int regardless of the
6:32
value of people regardless of the types
6:34
of a and B this is because NBC logical
6:38
assertion the type of illogical
6:41
assertion is that it is either true or
6:43
rated it corresponds to a boolean value
6:46
their foot the type of an A and then be
6:50
regardless of what a and B are the
6:53
result is always 0 or 1 so it is of type
6:56
in now you can print the result is an
6:59
int you can see print of persons day and
7:02
then now there are three logical
7:08
operations as i mentioned so that is
7:09
also are in see it is denoted by two
7:13
vertical bars which are there on your
7:17
people so a or b which is a bar b
7:22
evaluates to non zero if either is non 0
7:30
or B is nonzero if both of them are 0
7:33
then the resulting civil so this is the
7:35
meaning of a logical operation if both
7:38
of them are false then a or b is false
7:44
if at least one of them is true the new
7:47
york-based ok so you can write the truth
7:50
table for that if in BR 0 then the
7:53
output is sooo if is non 0 and b is any
7:57
value then you already know that that
8:00
output of a or b is one missile the
8:03
output is 1 and we will not be rendering
8:06
this is similar to in the case of and if
8:09
it was 0 and B was any other value then
8:12
you know that output offend is
8:13
little therefore we will not be a
8:16
relative similarly here if is nonzero
8:18
then you know the value is 1 so he will
8:22
not be valid and as before they are bees
8:27
of type in so the third logical
8:30
operation is not ok now not in c is
8:35
denoted as the ! so let's see an example
8:41
so not is the logical compliment and it
8:44
takes only one argument this is
8:46
different from the previous to that we
8:48
have seen a or b + a and B both took two
8:54
arguments it's not takes only one not
8:57
even so it is called a unitary operator
8:59
so not of a is an expression of type
9:03
integer and the value is the negation of
9:06
P so is 0 not of a will be one and if is
9:12
not 0 then not available be 0
9:15
ok so for example if I want to say that
9:21
is not divisible by thing i will just
9:23
write not of a mortar equal to 0 you
9:28
know that a martyr equal to 0 this for a
9:30
being divisible by 3 so negation of that
9:33
it will say that the given number is not
9:42
let's finish this by slightly
9:45
complicated example which is that of
9:50
ok so i am given a particular year
9:57
number and i want to say that the given
10:00
number is it corresponds to a leap year
10:03
on now what is a leap year it's that you
10:08
add a few year a few years we'll have
10:12
the ability 29 infallibility all of the
10:16
years will have 28 days infallibility so
10:19
what is the logical leap year so roughly
10:22
an average solar year is 360 5.24 2375
10:32
ok so in particular it's not an integer
10:35
so we normally say that a year has 365
10:39
days that's not quite prove its
10:42
surrounding ok so how much have been
10:45
losing so you can calculate it as
10:48
follows the remaining number after the
10:52
remaining a number after the decimal
10:54
point is a roughly 2.25 ok so that rough
10:58
cut let's say that every four years
11:00
because of this point to fight you will
11:04
okay so every year you are losing about
11:09
a quarter of a day so every four years
11:17
now when you do that you go back to so
11:35
so you have 365 point let's say 25 so
11:39
every four years you would lose four
11:44
years you lose about today approximately
11:51
ok so in order to compensate for that
11:55
you add one day every four years
12:03
ok so in in hundred years you would have
12:21
25days right but that is one day too
12:27
much because remember that this number
12:29
is only three 65.2 for something so in
12:32
hundreds you should have added only 24
12:34
days but now you added 25 days
12:38
ok so to compensate for that every
12:41
hundred years so every hundred years
12:48
skip adding the extra
13:02
okay so every four years you add one
13:05
extra day but every hundred years every
13:08
hundred here you don't have that
13:10
extremely is you skip it because you
13:12
would have added one more day then you
13:14
and then again you can look look at what
13:18
remains what remains is also roughly
13:20
point2 for ok which means that AV 400
13:27
ok if you do this adjustment you're
13:30
losing about today because every hundred
13:33
years you're losing about court already
13:35
from this point to 375 part so you do
13:38
the same logical in every 400 years so
13:52
so this is the logical to leave here
13:54
that we all know so how do we decide
13:57
whether a year will be up here
14:01
ok so the logic that I have outlined
14:04
just now says that if a year is a
14:07
multiple of four then it's a leap year
14:10
but if a year is a multiple of hundred
14:13
as well then it is not a leap year but
14:16
if it is a multiple of have 400 then it
14:18
is a limpiar ok so here is a pretty
14:21
complicated expression so every 40 sleep
14:25
here but skip every hundred here unless
14:28
it is also a 400-year ok and you can
14:32
write this expression and see it's
14:34
slightly complex as you can imagine so
14:37
if the first line the first expression
14:41
says that why is year is a multiple of 4
14:46
ok so if you're is divisible by 4 also
14:50
the following should be true it should
14:53
not be a multiple of hundred unless it
14:57
is a multiple of four hundred so it
14:59
should not be divisible by hundred that
15:03
should be true or it should be true that
15:05
the it should be a multiple of four
15:09
hundred for example if you have 400 then
15:13
ok so what will happen is that year
15:16
model for 400 model for is 0 then what
15:21
happens is that you have 400 more below
15:23
hundred that is 0 so this is equal to 0
15:29
that is one not of 1 is 0 so this part
15:36
is entirely 0 but it is divisible by 400
15:40
400 / 400 is 0 therefore this part is
15:44
true this are zero or one is true
15:48
therefore the whole expression becomes 1
15:51
and 1 so it is true
15:56
so this logical expression slightly
15:58
complicated logical expression and coats
16:01
the logic for saying that the given year
16:04
is suddenly appear so try this out
16:06
yourself this is a slightly tricky
16:08
expression and convince yourself that
16:11
this exactly in quotes the logical you
No comments:
Post a Comment