Learn Programming Technique C to Master Skills - Nested If Statement Program

  • 2 days ago
Transcript
00:00Hi, in the last video I have explained about to display the greatest value out of three.
00:09This is the flowchart of it which I have explained how to display the greatest value, how the
00:16condition going to check and will get the greatest value.
00:20Now I'm going to make the program in C.
00:22Let us see how to make it.
00:28First of all what I have to do is to compare first value with the second and with the third.
00:46For that I will use first of all hash include, stdio.h, use the main, int main and inside
01:00it I will take variables a, b and c.
01:05I will use a statement printf input three numbers from keyboard like this and I will
01:26use the scanf, how many type of specifiers, three, %e, %d, %e, the first value is going
01:38to store inside where a, so I will use and a, the second one in b, the third one in c.
01:47So what approach we should take, first of all compare a with b if a greater than b and
01:55again continuously if a greater than c, so continuously we are taking decision.
02:03If a greater than b then immediately we have compared a with c and both the cases if the
02:10condition is true, so I will display greatest value is that is what %e where it is inside
02:23c.
02:26Now here if the condition is true and when it come to check the second one here the condition
02:32get false, so for the second if statement we have to apply the else part, so here else
02:43and what it should display inside the else part of the second if statement printf slash
02:50n greatest value is %e where it is inside what c, so here should be what if a greater
03:05than b and if a greater than c, so what I should write here a.
03:13So if a is greater than b and if a is greater than c, if it is greater than b and what c
03:20both and it is going to display what a, the value which is there inside a, here if the
03:26condition is true a greater than b but the value which is there inside a is not greater
03:31than c that it means what c is greater than a and as well as what b, so in the else part
03:41what is going to display greatest value is what c.
03:44Now let us come to this else part okay, when the work of the above statement is also completed
03:56that is this okay, for the first if statement there will be what else part, so it's disclosed
04:07here and again if what b greater than c, in this case printf slash n greatest is %e
04:26and where it is, it is inside b okay and if the condition get false it will come to the
04:32else part of the second if and what printf slash n greatest is %e where it is inside
04:47c okay, now we have to apply the return 0 for exit status, so here I will use what return
05:030 okay, just check out if a is greater than a, if it is greater than c okay, it is greater
05:12than b as well as with c, so it's going to display the greatest value which is there
05:17inside a, if here the condition is true but here the condition get false, a greater than
05:23c it's not the condition it should be what c greater than a okay, a greater than c here
05:31if the condition is what false, so in that case here it's true but here if the condition
05:41get false, it's going to come to the else part and what's going to display c okay, now
05:49if at the initial stage if the condition get false, if a is greater than b, if the condition
05:55get false here, immediately it's going to come to the else part, so here this open braces
06:02first of all going to close here okay and here is the else part where it's again going
06:10to check if b greater than c, in that case greatest is what b okay, otherwise what the
06:20else part greatest is what c okay, so let us run the program and see is it working or
06:33not, there are lot of errors showing, what expected semicolon before, so here I haven't
06:42used, so not lot of error only a single error, here I have to use what semicolon, I will
06:49save it and again click on build, so now it's showing me zero error and zero warning, now
06:57let us try to run and see will it give the correct result, 9 is the first value, 6 is
07:04the second, 2 is the third, so it should display what 9 okay, I am going to run it again and
07:13with some different values, suppose here what 7, then 9, then 2, again it's going to display
07:199, again run the program one more time, if I run it, if I give what here the first one is 7,
07:26and 5 and 11, so what it should display 11 okay, so this is the program, maybe it's possible that
07:38either for the first time you may not understand it but when you will see this video again and
07:45repeat, so you are able to understand it okay, so thank you all of you, bye.

Recommended