Java/C2/Relational-Operations/English-timed
From Script | Spoken-Tutorial
Time' | Narration |
00:02 | Welcome to the spoken tutorial on Relational Operators in C and C++. |
00:07 | In this tutorial, we will learn about: |
00;09 | Relational operators like |
00:12 | Less than: eg. a < b |
00:15 | Greater than: eg. a > b |
00:18 | Less than or equal to: eg. a <= b |
00:23 | Greater than or equal to: eg. a >= b |
00:28 | Equal to: eg. a == b |
00:31 | Not equal to: eg. a != b |
00:38 | To record this tutorial, I am using: Ubuntu 11.10 as the operating system |
00:43 | gcc and g++ Compiler version 4.6.1 in Ubuntu. |
00:50 | Let us begin with an introduction. |
00:53 | Relational operators are used to compare integer and floating point numbers. |
00:58 | Expressions using relational operators return 0 for false and 1 for true.
Return values: 0 when False 1 when True |
01:04 | Now I will demonstrate the relational operators with the help of a C program. |
01:10 | I have already made the program. |
01:11 | So, I'll open the editor and explain the code. |
01:16 | First, we declare two variables a and b. |
01:21 | This printf statement prompts the user to enter the values of a and b. |
01:27 | This scanf statement takes input for the variables a and b. |
01:33 | Now we have the greater than operator. |
01:35 | This operator compares the two operands on either side of the operator. |
01:39 | It returns' False if a is greater than b. |
01:44 | This printf statement is executed if the above condition is true. |
01:48 | If the above condition is false then it is skipped. |
01:51 | To control then jumps to the next statement. |
01:54 | We now have the less than operator. |
01:56 | This too compares the operands. |
01:58 | It returns true when a is less than b. |
02:03 | This printf statement is executed if the above condition is true. |
02:07 | It is skipped otherwise. |
02:09 | Let's execute the code till here. |
02:13 | First comment out the following. Type /* */ |
02:24 | Click on Save. |
02:26 | I have saved my file as relational.c |
02:30 | Open the terminal window by pressing Ctrl, Alt and T keys simultaneously. |
02:36 | To compile, type the following on the terminal gcc relational.c -o rel |
02:50 | Press Enter. |
02:52 | To execute type ./rel Press Enter.
|
02:58 | I enter a as 8 and b as 3. |
03:02 | The output is displayed: |
03:04 | 8 is greater than 3. |
03:07 | You can try executing this code with different values of a and b. |
03:12 | Coming back to the code. |
03:14 | Delete the comment from here and put it here.
|
03:24 | Now we have the less than or equal to operator. |
03:29 | This operator compares the two operands on either side of the operator. |
03:33 | It returns true if a is less than or equal to b. |
03:39 | This printf statement is executed if the above condition is true. |
03:43 | If the above condition is false then it is skipped. |
03:46 | The control then jumps to the next statement. |
03:50 | Next comes the greater than or equal to operator. |
03:53 | It compares a and b and returns true if a is greater than or equal to b. |
04:01 | If the condition is true then this printf statement will be executed. |
04:05 | Now let's execute the code till here. |
04:08 | Click on Save. |
04:10 | Switch back to the terminal. |
04:12 | Compile and execute as before.
|
04:17 | I enter a as 8 and b as 3. |
04:23 | The output is displayed: |
04:25 | 8 is greater than or equal to 3 |
04:30 | Now Coming back to rest of the code. |
04:33 | Delete the multiline comments from here ands here. |
04:43 | we now have the equal to operator. |
04:47 | It is denoted by double equal (==) signs. |
04:50 | This operator returns true when both operands are equal to one another. |
04:57 | This printf statement executes when a is equal to b. |
05:01 | If not, the control then jumps on to the next statement. |
05:06 | Similarly, we have the not equal to operator. |
05:09 | This operator returns true when the operands are not equal to one another. |
05:15 | This printf statment will execute when a is not equal to b. |
05:21 | Coming to the end of the program.
Return 0; |
05:24 | Click on Save. |
05:26 | Switch back to the terminal. |
05:28 | Compile and execute as before.
|
05:33 | Enter a as 8 and b as 3. |
05:39 | The output is displayed on the screen: |
05:41 | 8 is not equal to 3 |
05:45 | So, we see how the relational operaotors work. |
05:48 | Try executing this code with different set of inputs. |
05:52 | \Now, writing a smilar program in C++ is quite easy. |
05:56 | There are a few differences in the syntax. |
06:00 | I have already made the code in C++. |
06:04 | Their is the code for relational operators in C++. |
06:09 | Notice that the header is different. |
06:12 | Also we have the using statement here. |
06:16 | The output statement in C++ is cout. |
06:19 | And the input statement in C++ is cin. |
06:22 | So, apart from these differences, the two codes are very similar. |
06:27 | Click on save. |
06:29 | Please make sure the file is saved with the extension .cpp |
06:33 | I have saved my file as relational.cpp |
06:38 | Let's compile the code. |
06:40 | Open the terminal and type g++ relational.cpp -o rel1 |
06:51 | To execute Type './ rel1, Press Enter.
|
06:57 | I enter a as 8 and b as 3. |
07:01 | The output is displayed: |
07:03 | We see that the output is same as the one in C code. |
07:08 | Now let us see an error which we can come across. |
07:11 | Come back to the program |
07:13 | Suppose here we replace the double equal to sign with the single equal to. |
07:20 | Click on Save. |
07:21 | Come back to the terminal. |
07:24 | Compile and execute as before. |
07:34 | Here we see it is showing 3 is equal to 3. |
07.38 | Come back to our program |
07:40 | This is because here we have an assignment operator. |
07:44 | So value of b is assigned to a. |
07:47 | Now Let us fix this error. |
07:49 | Type an equal to sign. |
07:52 | Click on Save |
07:55 | Switch back to the terminal |
07:56 | compile and execute as before. |
08:04 | The output is now correct. |
08:06 | Let's summarize the tutorial. |
08:09 | In this tutorial, we learnt |
08:10 | Relational operators like |
08:12 | Less than: eg. a b |
08:18 | Less than or equal to: eg. a<=b |
08:23 | Greater than or equal to: eg. a>=b |
08:27 | Equal to: eg. a==b |
08:30 | Not equal to: eg. a!=b |
08:34 | As an assignment |
08:35 | Write a program that takes the marks of three students as input. |
08:40 | Compare the marks to see which student has scored the highest. |
08:44 | Check also if two or more students have scored equal marks. |
08:49 | Watch the video available at the following link |
08:51 | It summarises the Spoken Tutorial project |
08:54 | If you do not have good bandwidth, you can download and watch it
|
08:58 | The Spoken Tutorial Project Team |
09:00 | Conducts workshops using spoken tutorials |
09:03 | Gives certificates for those who pass an online test |
09:06 | For more details, please write to contact at spoken hyphen tutorial dot org
|
09:14 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
09:18 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
09:24 | More information on this Mission is available at |
09:27 | spoken hyphen tutorial dot org slash NMEICT hyphen Intro
|
09:35 | This is Ritwik Joshi from IIT Bombay.
Thank you for joining. |