Video není dostupné.
Omlouváme se.

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

Sdílet
Vložit
  • čas přidán 6. 06. 2021
  • 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!

Komentáře • 21

  • @justcurious1940
    @justcurious1940 Před 7 měsíci +1

    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 Před rokem +1

    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  Před rokem

      I'm glad you enjoyed it! :-) Thanks for the suggestion, maybe one day I'll do something like that.

  • @SketchupGuru
    @SketchupGuru Před rokem +2

    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  Před rokem +2

      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 Před 7 měsíci +1

    These are great little exercises, but I find myself having to constantly pause to keep up with your speed

  • @nour1144
    @nour1144 Před 8 měsíci

    What if we wanted the program to print which numbers were repeated without us typing the numbers

  • @andrejpoljakovic5482
    @andrejpoljakovic5482 Před rokem +1

    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!

    • @Mkhuss
      @Mkhuss Před 9 měsíci

      u have to hash in this case

    • @justcurious1940
      @justcurious1940 Před 7 měsíci

      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 Před 6 měsíci

      please do it for us😅@@justcurious1940

  • @x9bq
    @x9bq Před rokem

    How to find items are less than 100 for example and print “ there 5 items less than 100 “

  • @zhenghaokang436
    @zhenghaokang436 Před rokem +1

    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  Před rokem +3

      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: czcams.com/video/1OZMcC0euic/video.html. :-)

  • @chandu1969
    @chandu1969 Před 6 měsíci

    sir please say how to find all elements counts please sir🙏🙏🙏.

  • @boborafg5632
    @boborafg5632 Před rokem +1

    How can i count the values between 5 and 8 ( example)?

    • @PortfolioCourses
      @PortfolioCourses  Před rokem +2

      Great question! :-) We could have the if-statement look something like this:
      if (array[i] >= 5 && array[i]

    • @boborafg5632
      @boborafg5632 Před rokem

      @@PortfolioCourses thanks, but do u also know how i can get the first occurrence higher than 7 in a array.

    • @PortfolioCourses
      @PortfolioCourses  Před rokem +1

      @@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 Před rokem +1

      @@PortfolioCourses yes but then i get all values higher than 7
      . I want the first value higher than 7

    • @PortfolioCourses
      @PortfolioCourses  Před rokem +1

      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. :-)