Skip to player
Skip to main content
Skip to footer
Search
Connect
Watch fullscreen
Like
Bookmark
Share
Add to Playlist
Report
Learn Programming Technique C to Master Skills - Second Program of Loop ( For Loop )
Tutorials Arena
Follow
10/17/2024
Category
š
Learning
Transcript
Display full video transcript
00:00
Hello everyone, today I am going to explain this program with the use of for loop that
00:09
is to display the square of first three odd numbers 1, 9 and 25.
00:16
The last video I have explained with the use of while loop.
00:23
So let me open the code blocks.
00:29
So in a code block I am going to create a new file and I am going to save it also, so
00:37
I am going to file and save file, I will give a name to prg2c, prg2b something like this
00:49
2c.
00:50
Let us give the name to it and click on save, use hash include stdio.h, inside it I am going
01:01
to use int main and I am going to take the variables int sq, od and then what i, I will
01:12
initialize the value of od and I will apply the loop i equals to 1, i less than equal
01:20
to 3 and then what i, plus plus.
01:25
Now what should I do, I use what sq equal to od into od, so the square is going to store
01:33
inside sq and I will print it that is slash n square of odd number is percent d where
01:46
it is inside sq, so it's going to display and then I need the next odd number, so I
01:54
will write down od equals to od plus 2 okay and in this way the loop will carry on and
02:02
get the result, so I will just choose here return zero and we will see, I will click
02:10
on build and run it, so it displayed 1, 9 and 25.
02:16
So how the things work, let us understand I have taken three variables sq, od and i,
02:22
the value of od is 1, this loop will carry on for three times, what is inside i, value
02:28
of i is 1, 1 less than 3, the condition is true.
02:34
Now what is inside od, it is 1, so 1 into 1, so the resulted value is 1 which is going
02:39
to store inside sq and then it's going to display, so first of all 1 is going to display
02:46
then 1 plus 2, a new value inside od is 3 okay, the value of i is going to increment
02:53
by 1 that is what 2, so now the new value of i is 2, 2 less than 3, the condition is
03:00
true, inside od it is 3, so 3 into 3 that is what 9, so 9 is going to store inside sq,
03:08
it will display square of odd number is that is what 9 okay, then what 3 plus 2, a new
03:17
value inside od it is 5, again it's going to increment the loop, so the value of i will
03:24
be what 3, it will come to the decision part, 3 equal to 3, the condition is true, what
03:31
inside od it is 5, so 5 into 5, 25, a new value inside sq is what 25, it's going to
03:38
display what 25, then 5 plus 2, 7 okay, the value of i increment by 1, from 3 it will
03:48
be what 4, 4 less than 3, condition false, this loop will terminate, the for loop will
03:54
terminate okay, so we will get what 1, 9 and 25.
Recommended
0:38
|
Up next
How To Fold Bath Towels- Martha Stewart-HQDXWj50pdE
Martha Stewart
12/26/2017
4:07
Learn Programming Technique C to Master Skills - Second Program of Loop (While Loop)
Tutorials Arena
10/17/2024
3:51
Learn Programming Technique C to Master Skills - First Program of Loop (For Loop)
Tutorials Arena
10/13/2024
3:55
Learn Programming Technique C to Master Skills - First Program of Loop (While Loop)
Tutorials Arena
10/13/2024
4:28
Learn Programming Technique C to Master Skills - Fourth Program of Loop ( For Loop )
Tutorials Arena
10/13/2024
5:33
Learn Programming Technique C to Master Skills - Fourth Program of Loop ( While Loop )
Tutorials Arena
10/13/2024
3:52
Learn Programming Technique C to Master Skills - Second Program of Loop (Flow Chart)
Tutorials Arena
10/17/2024
8:01
Learn Programming Technique C to Master Skills - Loop Within Loop Program
Tutorials Arena
10/17/2024
8:07
Learn Programming Technique C to Master Skills - Loop with if Statement Second Program
Tutorials Arena
10/17/2024
3:51
Learn Programming Technique C to Master Skills - First Program of Loop (Flowchart)
Tutorials Arena
10/13/2024
3:27
Learn Programming Technique C to Master Skills - Third Program of Loop ( Flow Chart)
Tutorials Arena
10/17/2024
5:02
Learn Programming Technique C to Master Skills - Third Program of Loop
Tutorials Arena
10/17/2024
4:57
Learn Programming Technique C to Master Skills - Loop With If Statement Program ( Flow Chart )
Tutorials Arena
10/13/2024
10:56
Learn Programming Technique C to Master Skills - Loop With If Statement Program
Tutorials Arena
10/13/2024
4:01
Learn Programming Technique C to Master Skills - Fourth Program of Loop ( Flow Chart )
Tutorials Arena
10/13/2024
9:09
Learn Programming Technique C to Master Skills - Second Program( Call by Reference)
Tutorials Arena
11/8/2024
6:03
Learn Programming Technique C to Master Skills - Linked List ( Second Program)
Tutorials Arena
11/30/2024
4:57
Learn Programming Technique C to Master Skills - Loop with If Statement Second Program Continue...
Tutorials Arena
10/17/2024
7:02
Learn Programming Technique C to Master Skills - Sixth Program of Array (Loop with if)
Tutorials Arena
11/1/2024
2:34
Learn Programming Technique C to MasterĀ Skills - Second Program of Function ( Return Val) - I
Tutorials Arena
11/3/2024
8:18
Learn Programming Technique C to Master Skills - Loop Within Loop Program Explanation in Flow chart
Tutorials Arena
10/17/2024
11:41
Learn Programming Technique C to Master Skills - Second Program of Array
Tutorials Arena
11/1/2024
5:59
Learn Programming Technique C to Master Skills - File Handling Second Program (Continue..)
Tutorials Arena
11/18/2024
3:16
Learn Programming Technique C to MasterĀ Skills - First Program of Function ( Continue ...)
Tutorials Arena
11/3/2024
6:12
Learn Programming Technique C to Master Skills - Second Program(Array with Function , Call by Reference)
Tutorials Arena
11/9/2024