Thread: A simple Code To count frequency of numbers in an array..

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    1

    A simple Code To count frequency of numbers in an array..

    hi every1 i m trying to write a simple code to count the no. of times a no. repeats in an array.....so plzzz try some logics!! without using any builtin function

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by aaditg
    hi every1 i m trying to write a simple code to count the no. of times a no. repeats in an array.....so plzzz try some logics!!
    So, what is your plan and what have you done so far?

    Quote Originally Posted by aaditg
    without using any builtin function
    In a way, there are no built-in functions in C++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Kathmandu
    Posts
    4
    I hope this source code will help u.

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int array[14]={1,1,3,4,2,64,2,3,1,3,4,53,5,6},num,i,count=0;
        cout<<"Enter the number you want to count: ";
        cin>>num;
        for(i=0;i<=13;++i)
        {
            if(array[i]==num)
               ++count;          //Increase the count, if number matches array
        }
        cout<<"The number of repition of "<<num<<" is "<<count<<" times";
        return 0;
    }

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    programiz: please do not give code handouts prematurely.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by programiz View Post
    "The number of repition of "
    I think you need a bit more repetition there.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch Case for Counting Frequency of numbers
    By sjmp in forum C Programming
    Replies: 11
    Last Post: 07-30-2012, 12:35 PM
  2. count and print the frequency of each ASCII character
    By s_jsstevens in forum C Programming
    Replies: 3
    Last Post: 02-07-2011, 09:33 PM
  3. Replies: 9
    Last Post: 03-13-2010, 03:40 AM
  4. very simple code to match letters to numbers
    By kop442000 in forum C Programming
    Replies: 14
    Last Post: 07-24-2009, 05:16 PM
  5. I'm trying to count the frequency of the phrase "ing"
    By thefreeman1159 in forum C Programming
    Replies: 14
    Last Post: 09-23-2008, 11:58 AM