Count the Occurrences of a Value in an Array | C Programming Example

  Рет қаралды 29,102

Portfolio Courses

Portfolio Courses

3 жыл бұрын

An example of how to count the occurrences of a value in an array using C. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Пікірлер: 21
@justcurious1940
@justcurious1940 6 ай бұрын
Nice Serie , Thanks : int Occurences (int *array,int length,int to_find){ int count = 0; for(int i = 0 ; i < length ; i++){ if(array[i] == to_find){ ++count; } } return count; }
@naboulsikhalid7763
@naboulsikhalid7763 Жыл бұрын
very enjoyable to watch and learn at the same time. I would like to see if at the end of each lesson you throw an exercise with additional complexity for practice and get more interaction with your followers(Learners like me). thank you
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad you enjoyed it! :-) Thanks for the suggestion, maybe one day I'll do something like that.
@SketchupGuru
@SketchupGuru Жыл бұрын
Hi, great video! I've learned a lot from these exercise videos and i understand the logic as well. After each video, i try to create these codes on my own and it's been a great learning experience. Thankyou for sharing this information!! Quick question though: once I'm done with this exercise playlist, how do I progress further? Do these exercise questions get asked in Interviews? And could you share an example of these exercises are used in real life projects or applications? Thanks in advance:)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I would suggest progressing further by working on your own "side projects". Try to build something you're interested in building, for example a game, or some utility tool. There are lists of "project ideas" online. In the process of building a project you'll find that you'll need to self-learn other topics, but that's an incredibly useful process that's similar to working on "real-world commercial projects" where you'll need to do the same. Some of these exercises likely get asked in interviews, yes. Regarding real-world applications, in the case of some exercises there are many, and in others there are not many at all. :-) So something like Fizz Buzz is based off a children's game and is helpful in terms of teaching us how to think through a simple problem. Other exercises like say Quicksort are used all the time as part of standard libraries to sort anything from a list of files to a playlist, etc.
@food_fondler
@food_fondler 7 ай бұрын
These are great little exercises, but I find myself having to constantly pause to keep up with your speed
@andrejpoljakovic5482
@andrejpoljakovic5482 Жыл бұрын
Great video. I have a question. How do you find the number of all repeated values in an array which size is given by the user and the numbers are random numbers? Example n=10, a[n]={1,1,2,2,3,3,3,4,4,4} and i need it to print the number of occurrences of every number in the array. Thank you!
@SMDB-bd
@SMDB-bd 8 ай бұрын
u have to hash in this case
@justcurious1940
@justcurious1940 6 ай бұрын
Each time u find an occurrence u will have to update the array, and this process could be a pain in C , kind off , I'm not sure , I' don't wanna give this one a shot right now , but if u insist I can sacrifice my time to solve this one ;
@rupamsengupta1467
@rupamsengupta1467 6 ай бұрын
please do it for us😅@@justcurious1940
@nour1144
@nour1144 7 ай бұрын
What if we wanted the program to print which numbers were repeated without us typing the numbers
@zhenghaokang436
@zhenghaokang436 Жыл бұрын
How can i count all the numbers: 0~9; make the output like : 0s found 0; 1s found 1; 2s found 1; 3s found 0....... 9s found
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question Zhenghao! :-) There are a number of ways you could do this. One way would be to have 10 variables, one for each number, to keep a count of each number. You could then have inside the loop that loops through the array an if control structure like this: if (array[i] == 0) zero_counter++; else if (array[i] == 1) one_counter++; ... and so on ... You could use a switch here instead. You could also use an array to keep track of the counts using an array. So something like: int counts[10]; where counts[0] keeps track of the count of occurrences of 0, counts[1] keeps track of the count of occurrences of 1, and so far. Those are just some ideas though. This video on counting each letter in a string might give you some ideas too: kzbin.info/www/bejne/Z4C9fpZ5Zcqon8U. :-)
@boborafg5632
@boborafg5632 Жыл бұрын
How can i count the values between 5 and 8 ( example)?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question! :-) We could have the if-statement look something like this: if (array[i] >= 5 && array[i]
@boborafg5632
@boborafg5632 Жыл бұрын
@@PortfolioCourses thanks, but do u also know how i can get the first occurrence higher than 7 in a array.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@boborafg5632 That would probably be something like this: if (arrray[i] > 7) return array[i]; or possibly return i; instead if you are looking for the index of that element.
@boborafg5632
@boborafg5632 Жыл бұрын
@@PortfolioCourses yes but then i get all values higher than 7 . I want the first value higher than 7
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Well if you want the first value higher than 7, you either need to store that value in an array or return the value from a function, or stop the loop when it finds the value, or *something* like that. Exactly what you do is up to you, but that if-statement there is the general idea. :-)
@x9bq
@x9bq Жыл бұрын
How to find items are less than 100 for example and print “ there 5 items less than 100 “
@chandu1969
@chandu1969 5 ай бұрын
sir please say how to find all elements counts please sir🙏🙏🙏.
Reverse An Array | C Programming Example
7:34
Portfolio Courses
Рет қаралды 29 М.
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 108 МЛН
Мы никогда не были так напуганы!
00:15
Аришнев
Рет қаралды 6 МЛН
Looks realistic #tiktok
00:22
Анастасия Тарасова
Рет қаралды 97 МЛН
Counting Occurrences Of A Word In A String | C Programming Example
14:56
Portfolio Courses
Рет қаралды 17 М.
Counting the Vowels in a String | C Programming Example
9:50
Portfolio Courses
Рет қаралды 14 М.
Inserting an element in an array (C program)
7:16
CSE GURUS
Рет қаралды 83 М.
Find The Frequency Of Each Letter In A String | C Programming Example
16:07
C Program To Check Repetition of Digit In A Number using Arrays
11:17
Where Does Bad Code Come From?
42:21
Molly Rocket
Рет қаралды 185 М.
Check If A String Is A Palindrome | C Programming Example
10:56
Portfolio Courses
Рет қаралды 35 М.
小天使和小丑离家出走#short #angel #clown
0:36
Super Beauty team
Рет қаралды 25 МЛН
ТАМАЕВ УНИЧТОЖИЛ CLS ВЕНГАЛБИ! Конфликт с Ахмедом?!
25:37
Тайка и Борщ | Телега "Легенда о Захаре" #еда
0:20
Легенда о Захаре
Рет қаралды 1,6 МЛН
Look at two different videos 😁 @karina-kola
0:12
Andrey Grechka
Рет қаралды 5 МЛН