Skip to player
Skip to main content
Search
Connect
Watch fullscreen
Like
Bookmark
Share
More
Add to Playlist
Report
Learn Programming Technique C to Master Skills - Fourth Program of Array
Tutorials Arena
Follow
1 year ago
Category
📚
Learning
Transcript
Display full video transcript
00:00
Hello everyone, now I'm going to make program the fourth one, that is input five numbers
00:08
in an array and display number of occurrence or frequency of any number, maybe it existing
00:17
for one time, maybe it is existing for two times in an array okay, so to count that number
00:23
and to display that how many times its occurrence is there inside the array or what is its frequency
00:29
that is the program, so the fourth number program I'm going to explain okay, I'm going
00:37
to make, first thing I will do to include the header file okay, I will quickly go and
00:58
save it, I have given the name to it, now what I require, first of all I will take st5
01:14
okay, as I have to input the percentage of five strands, then I will take one variable
01:22
num okay, so that it will count that particular number exists for how many times, so I have
01:30
to input five numbers in an array and then I have to see that which number occurrence
01:36
is more than one time, then I need what I, I will see that what else we can take okay,
01:45
so here I will use printf one of the statement and give here write here what, enter values
01:57
in array okay, like this okay and at the end I will use semicolon, so I will use what scanf
02:05
but before scanf I will apply the loop i equals to zero, i less than equals to four and what
02:13
I plus plus okay, I will carry on the loop for the five times and use the scanf okay,
02:20
and here it will be what percent d, where it's going to store inside st i okay, now the value
02:31
is going to store in the index position of an array, first zero then one then two and three
02:37
like this five, all the five values are going to store, what we have to see, we have to see
02:43
that how many occurrence is there of a particular number, so what I will do, I will write a message
02:55
enter any number okay, so I am going to input any number from the keyboard with a scanf
03:06
percent d, and num okay, now I will apply the again the loop i equals to zero, i less than
03:21
equals to four and i plus plus okay, and inside if what, if number which is entered that is
03:35
equal equal to what st i okay, the number which is there inside the num is it equal to the value
03:51
which is there inside the index position of an array, if it's equal okay, so you have to count
03:57
it, so to count it I will take one variable, let us take here what for counting n okay,
04:05
so I will use what n plus plus like this and here at the top I have to take one variable n okay,
04:15
to count occurrence of the presence of the number and n equal to zero also, so what will
04:27
happen if that number exists inside any one of the index position of an array that number is
04:35
going to count okay, by n plus plus, the loop will complete, when the loop will terminate then
04:43
I will use what printf, we can write on frequency of number entered is percent d comma n okay,
05:01
so this is the program and here I will use what return zero, so let's hope everything is fine,
05:11
I click on build and then run, let's ask me to enter value in array okay, I have just entered
05:19
what 33 and 50 okay, then again 33 and 70 okay, and then 11 okay, I am gonna press enter,
05:35
oh some mistakes there, let me see, why it is showing me the error okay, I haven't used the
05:53
ampersand and sign here okay, so that's the mistake, so let us click on build, again done it,
06:03
again input the values inside the array okay, so let me input 33, so the frequency of a number
06:18
entered is 2, so 33 occurrence is what how many times, two times okay, it's showing the correct
06:27
result, let me run one more time, 33, 11, 33, 11, 33 okay, and 44 something like this,
06:39
so I have to okay, I haven't input extra numbers, let me again run it, 33, 22, 11 and 33,
06:57
four numbers and one more 5 okay, so enter the value, suppose I input what 33, so it's going to
07:04
display what, the occurrence is how many times, two times, so it's working fine okay, and let
07:13
us understand the logic, so first of all I have taken this st5, so what will happen inside the
07:20
memory, there will be five locations which are going to create okay, let me create the five
07:31
locations okay, this will be the zeroth location, this will be the first location, this will be the
07:44
second location, 0, 1, 2 and this will be the fourth and fifth okay, so if I will write this
07:56
will be what here, what st0 okay, this will be what st1, this will be what st2, this will be st3
08:15
and this one will be what st4 okay, so at the declaration the spaces are going to allocate,
08:26
now I have applied the loop, so suppose I will put here what 33 and here what 11 and again what
08:34
33 okay, and here it's what suppose 44 and here it's what 55 okay, so these numbers are stored
08:51
when I have applied this loop okay, so we all know how to run the loop and to store the values
09:04
inside the array okay, I have given a message here to enter any number from the keyboard,
09:10
suppose I input what 33 okay, now the loop will carry on, the value of y is 0, 0 less than 4,
09:16
the condition is true, what is inside now, it is 33, it is going to compare with the value which
09:22
is there at the zeroth position, index position of an array, let us see what is there, it is 33,
09:28
the 33 equals to 33, the condition is true, I have taken extra variable and value I have
09:35
already initialized it towards 0, so because of n++, now the value of n become 1 okay,
09:42
now value of i is going to increment from 0 to 1, 1 less than 4, so we are talking about the
09:51
first position here, here it's what 11, so what will happen, the condition will get false,
09:57
inside now, it's 33, inside st1, it is what 11, so 33 equal to 11, the condition get false,
10:07
so this counter variable is not going to increment okay and directly the value will
10:15
increment of i, so the value of i will be what 3, sorry 2, 2 less than 4, the condition is true,
10:22
what is there inside the second position, it is 33 okay, again the condition will get false,
10:28
33 equal to the third position of an array 33, condition is true, so the incrementation of n
10:35
is going to increment from 1 to 2, so there are 2 times when 33 occurs in an array okay,
10:45
the value of i is will be what 3, 3 less than 4, so we are talking about the third position,
10:52
this one, post 44 is installed okay, here in the third position, so what will happen,
11:01
inside now, it's 33, so 33 equal equals to sti position okay, suppose if I input inside num
11:10
is 33, it's going to compare with the sti position and that is what the second position
11:18
okay, that is here this 2, the condition is true, so what, it's going to count
11:26
yn++, so the value of yn will be what 2, so when the condition is true, it's going to count,
11:33
when the condition is not true, when the value inside num is not equal to the index position of
11:40
array, so this counting is not going to happen, n is not going to increment okay,
11:46
then this way it will compare with the third position value,
11:50
it is going to compare with the fourth position value okay, now inside
12:00
as we have mentioned n++, so the value of n will be what 2, so after the termination of the loop
12:08
okay, the final value is inside n that how many of them, which number occurred for more than
12:18
one time that is there inside n, so when this loop terminate, it's going to display
12:24
how many times that number exist inside the array okay.
Be the first to comment
Add your comment
Recommended
9:40
|
Up next
Learn Programming Technique C to Master Skills - Fifth Program of Array
Tutorials Arena
1 year ago
9:58
Learn Programming Technique C to Master Skills - Third Program of Array
Tutorials Arena
1 year ago
11:41
Learn Programming Technique C to Master Skills - Second Program of Array
Tutorials Arena
1 year ago
12:26
Learn Programming Technique C to Master Skills - First Program of Array
Tutorials Arena
1 year ago
7:35
Learn Programming Technique C to Master Skills - Fourth Program of Function
Tutorials Arena
1 year ago
13:04
Learn Programming Technique C to Master Skills - Double Dimension Array Program
Tutorials Arena
1 year ago
4:22
Learn Programming Technique C to Master Skills - Pointer And Arrays Program
Tutorials Arena
1 year ago
12:03
Learn Programming Technique C to Master Skills - Array of Structure Program
Tutorials Arena
1 year ago
3:40
Learn Programming Technique C to Master Skills - Array of Pointer Program
Tutorials Arena
1 year ago
7:30
Learn Programming Technique C to Master Skills - Fifth Program of Function
Tutorials Arena
1 year ago
7:02
Learn Programming Technique C to Master Skills - Sixth Program of Array (Loop with if)
Tutorials Arena
1 year ago
6:40
Learn Programming Technique C to Master Skills - Explanation of Array
Tutorials Arena
1 year ago
7:10
Learn Programming Technique C to Master SkillsCharacter String Fourth Program
Tutorials Arena
1 year ago
9:14
Learn Programming Technique C to Master Skills - Fourth Program (Call by Reference)
Tutorials Arena
1 year ago
5:02
Learn Programming Technique C to Master Skills - Third Program of Loop
Tutorials Arena
1 year ago
5:27
Learn Programming Technique C to Master Skills - Sixth Program of Function
Tutorials Arena
1 year ago
3:37
Learn Programming Technique C to Master Skills - Pointers And Arrays
Tutorials Arena
1 year ago
9:20
Learn Programming Technique C to Master Skills - Union Program
Tutorials Arena
1 year ago
5:33
Learn Programming Technique C to Master Skills - Fourth Program of Loop ( While Loop )
Tutorials Arena
1 year ago
4:28
Learn Programming Technique C to Master Skills - Fourth Program of Loop ( For Loop )
Tutorials Arena
1 year ago
9:47
Learn Programming Technique C to Master SkillsCharacter String Fifth Program
Tutorials Arena
1 year ago
4:51
Learn Programming Technique C to Master Skills - Seventh Program of Function - I
Tutorials Arena
1 year ago
4:01
Learn Programming Technique C to Master Skills - Fourth Program of Loop ( Flow Chart )
Tutorials Arena
1 year ago
8:08
Learn Programming Technique C to Master Skills - First Program of Function
Tutorials Arena
1 year ago
9:12
Learn Programming Technique C to Master Skills - Program of Recursion
Tutorials Arena
1 year ago
Be the first to comment