• 2 months ago
Transcript
00:00Hi, in the last video I have explained about how to display the first three odd numbers,
00:11how to display the square of first three odd numbers i.e. 1, 9 and 25.
00:16I have explained this program in the flowchart in the last video.
00:20Now today I am going to make the program in C.
00:23So let us see how to do it.
00:34I will open the new file that is cache include inside it what stdio.h and what int main and
00:47inside it I will take the variables.
00:50Before taking it, before taking the variables let us save it, let us say loop 2, 1, b, something
01:03like this I have given the name to it and save.
01:08I need the variables that is od, then sq, then i.
01:16I will initialize the value of od that is 1.
01:19I will initialize the value of i that is 1.
01:25Now I will apply the while loop while i less than equals to 3.
01:32How many times the loop is going to work for the 3 times that's why I apply i less than
01:37equals to 3.
01:38First thing what I will do, I will do the square of odd number that is od equals to
01:43od, then I will print the resulted value that is slash n square of odd number is that
01:59is where it is inside sq, then I will use od equals to od plus 2 and then i equals to
02:13i plus 1.
02:16This loop is going to carry on for 3 times and we are going to get the result and I am
02:22going to use what I have written 0, then I will save it.
02:29Let me click on build as there is zero error, let us run the program, so it's displayed
02:381, 9 and 25, I quickly understand it, the value of i it is 1, 1 less than 3 the condition
02:47is true, 1 into 1 what is inside sq it is 1, so 1 is going to print and 1 plus 2 it
02:56is what 3, so inside od it is 3, 1 plus 1 it is 2, what is inside i it is 2, the loop
03:04will carry on 2 less than 3, the condition is true, what is inside od it is 3, so 3 into
03:123, now the value inside sq will be 9, so 9 is going to print and what 3 plus 2 5 and
03:232 plus 1 3, again the loop will carry on as value of i is 3, 3 equal to 3 condition is
03:30true, what inside od it is 5, so 5 into 5 25, inside sq it will store the resulted value
03:40inside sq and then it's going to display that is 25, then 5 plus 2 7 and here 3 plus 1 4,
03:504 less than 3 condition false and this loop is going to terminate, but we will get the
03:57square of first 3 odd number it is 1, 9 and then 25.

Recommended