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

This is a discussion on will find number which is used frequently(often) in x array within the C++ Programming forums, part of the General Programming Boards category; will find number which is used frequently(often) in x array C++ Syntax (Toggle Plain Text) Code: int i; int x[i],frequency[i]; ...

  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
    682
    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.
    I never put signature, but I decided to make an exception.

  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
    682
    Quote Originally Posted by Mr.777 View Post
    I think kmdv explained well..
    I am wondering what is the point of this post.
    I never put signature, but I decided to make an exception.

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    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 bobknows's Avatar
    Join Date
    Jan 2011
    Location
    SD
    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, 07:28 AM
  5. Can't find the lowest number in array?
    By Nate2430 in forum C++ Programming
    Replies: 1
    Last Post: 11-20-2001, 09:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21