• 2 months ago
Transcript
00:00Hello everyone, now I'm going to make program the fourth one, that is input five numbers
00:08in an array and display number of occurrence or frequency of any number, maybe it existing
00:17for one time, maybe it is existing for two times in an array okay, so to count that number
00:23and to display that how many times its occurrence is there inside the array or what is its frequency
00:29that is the program, so the fourth number program I'm going to explain okay, I'm going
00:37to make, first thing I will do to include the header file okay, I will quickly go and
00:58save it, I have given the name to it, now what I require, first of all I will take st5
01:14okay, as I have to input the percentage of five strands, then I will take one variable
01:22num okay, so that it will count that particular number exists for how many times, so I have
01:30to input five numbers in an array and then I have to see that which number occurrence
01:36is more than one time, then I need what I, I will see that what else we can take okay,
01:45so here I will use printf one of the statement and give here write here what, enter values
01:57in array okay, like this okay and at the end I will use semicolon, so I will use what scanf
02:05but before scanf I will apply the loop i equals to zero, i less than equals to four and what
02:13I plus plus okay, I will carry on the loop for the five times and use the scanf okay,
02:20and here it will be what percent d, where it's going to store inside st i okay, now the value
02:31is going to store in the index position of an array, first zero then one then two and three
02:37like this five, all the five values are going to store, what we have to see, we have to see
02:43that how many occurrence is there of a particular number, so what I will do, I will write a message
02:55enter any number okay, so I am going to input any number from the keyboard with a scanf
03:06percent d, and num okay, now I will apply the again the loop i equals to zero, i less than
03:21equals to four and i plus plus okay, and inside if what, if number which is entered that is
03:35equal equal to what st i okay, the number which is there inside the num is it equal to the value
03:51which is there inside the index position of an array, if it's equal okay, so you have to count
03:57it, so to count it I will take one variable, let us take here what for counting n okay,
04:05so I will use what n plus plus like this and here at the top I have to take one variable n okay,
04:15to count occurrence of the presence of the number and n equal to zero also, so what will
04:27happen if that number exists inside any one of the index position of an array that number is
04:35going to count okay, by n plus plus, the loop will complete, when the loop will terminate then
04:43I will use what printf, we can write on frequency of number entered is percent d comma n okay,
05:01so this is the program and here I will use what return zero, so let's hope everything is fine,
05:11I click on build and then run, let's ask me to enter value in array okay, I have just entered
05:19what 33 and 50 okay, then again 33 and 70 okay, and then 11 okay, I am gonna press enter,
05:35oh some mistakes there, let me see, why it is showing me the error okay, I haven't used the
05:53ampersand and sign here okay, so that's the mistake, so let us click on build, again done it,
06:03again input the values inside the array okay, so let me input 33, so the frequency of a number
06:18entered is 2, so 33 occurrence is what how many times, two times okay, it's showing the correct
06:27result, let me run one more time, 33, 11, 33, 11, 33 okay, and 44 something like this,
06:39so I have to okay, I haven't input extra numbers, let me again run it, 33, 22, 11 and 33,
06:57four numbers and one more 5 okay, so enter the value, suppose I input what 33, so it's going to
07:04display what, the occurrence is how many times, two times, so it's working fine okay, and let
07:13us understand the logic, so first of all I have taken this st5, so what will happen inside the
07:20memory, there will be five locations which are going to create okay, let me create the five
07:31locations okay, this will be the zeroth location, this will be the first location, this will be the
07:44second location, 0, 1, 2 and this will be the fourth and fifth okay, so if I will write this
07:56will be what here, what st0 okay, this will be what st1, this will be what st2, this will be st3
08:15and this one will be what st4 okay, so at the declaration the spaces are going to allocate,
08:26now I have applied the loop, so suppose I will put here what 33 and here what 11 and again what
08:3433 okay, and here it's what suppose 44 and here it's what 55 okay, so these numbers are stored
08:51when I have applied this loop okay, so we all know how to run the loop and to store the values
09:04inside the array okay, I have given a message here to enter any number from the keyboard,
09:10suppose I input what 33 okay, now the loop will carry on, the value of y is 0, 0 less than 4,
09:16the condition is true, what is inside now, it is 33, it is going to compare with the value which
09:22is there at the zeroth position, index position of an array, let us see what is there, it is 33,
09:28the 33 equals to 33, the condition is true, I have taken extra variable and value I have
09:35already initialized it towards 0, so because of n++, now the value of n become 1 okay,
09:42now value of i is going to increment from 0 to 1, 1 less than 4, so we are talking about the
09:51first position here, here it's what 11, so what will happen, the condition will get false,
09:57inside now, it's 33, inside st1, it is what 11, so 33 equal to 11, the condition get false,
10:07so this counter variable is not going to increment okay and directly the value will
10:15increment of i, so the value of i will be what 3, sorry 2, 2 less than 4, the condition is true,
10:22what is there inside the second position, it is 33 okay, again the condition will get false,
10:2833 equal to the third position of an array 33, condition is true, so the incrementation of n
10:35is going to increment from 1 to 2, so there are 2 times when 33 occurs in an array okay,
10:45the value of i is will be what 3, 3 less than 4, so we are talking about the third position,
10:52this one, post 44 is installed okay, here in the third position, so what will happen,
11:01inside now, it's 33, so 33 equal equals to sti position okay, suppose if I input inside num
11:10is 33, it's going to compare with the sti position and that is what the second position
11:18okay, that is here this 2, the condition is true, so what, it's going to count
11:26yn++, so the value of yn will be what 2, so when the condition is true, it's going to count,
11:33when the condition is not true, when the value inside num is not equal to the index position of
11:40array, so this counting is not going to happen, n is not going to increment okay,
11:46then this way it will compare with the third position value,
11:50it is going to compare with the fourth position value okay, now inside
12:00as we have mentioned n++, so the value of n will be what 2, so after the termination of the loop
12:08okay, the final value is inside n that how many of them, which number occurred for more than
12:18one time that is there inside n, so when this loop terminate, it's going to display
12:24how many times that number exist inside the array okay.

Recommended