Thread: will find number which is used frequently(often) in x array

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    will find number which is used frequently(often) in x array

    will find number which is used frequently(often) in x array
    C++ Syntax (Toggle Plain Text)
    Code:
    int i;
    int x[i],frequency[i];
     
    for(int i=0;i<3;i++)
    {
    cin>>x[i];
    frequency[i]=0;
    }
     
    frequency[i]=0;
     
    for(int i=0;i<3;i++)
    {
    frequency[i]++;
    cout<<x[i];
    } 
    frequency[i]++;
    cout<<x[i];
    cout<<frequency[i];
    what should I do extra?



    there are array of numbers for example:
    I typed: 3
    I typed: 3
    I typed: 5

    and

    frequently number is: 3

    I want to write the code which will do it

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    1.
    Code:
    int i;
    int x[i],frequency[i];
    You can't declare arrays this way, i is unknown.
    Code:
    const int n = 3;
    int x[n];
    int frequency[n];
    2. The "i" in the first for loop hides the local "i". This is a different variable with the same name. Don't do this.

    3. The statement "frequency[i]=0;" which is outside of the loop is invalid. I have no idea what you wanted to achieve with this. You should remove it.

    4. The second loop should compare the current frequency (result of increment) with the frequency of the most frequent number (you need an additional variable for this).

    5. I have no idea what you want to achieve with the code, which is outside loop.

  3. #3
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    I think kmdv explained well..

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by Mr.777 View Post
    I think kmdv explained well..
    I am wondering what is the point of this post.

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    i am wondering what is the point of this post.
    I could say the same for unneccesary sarcasm to a newcomer
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    87
    is this a function or part of main?
    is the array ordered or not?

    this is an interesting question & might make a good exercise.
    ill keep tabs on this thread

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 08-16-2010, 10:00 AM
  2. Simple XOR Program
    By dolfaniss in forum C Programming
    Replies: 8
    Last Post: 05-24-2010, 01:27 PM
  3. can u help me with pointers?plzzzzzzzz
    By itcs in forum C Programming
    Replies: 7
    Last Post: 07-11-2003, 01:29 AM
  4. how do u find 2nd largest number??
    By juancardenas in forum C Programming
    Replies: 8
    Last Post: 02-14-2003, 08:28 AM
  5. Can't find the lowest number in array?
    By Nate2430 in forum C++ Programming
    Replies: 1
    Last Post: 11-20-2001, 10:21 AM