473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Frequency of elements in an array

5
I've just got a question which is very hard for me to do.
Here is the question:
In the program you are supposed to take the elements of an array which can be composed of 20 elements at max.When the array takes the value of -1 that means you end the array.Then you input the elements and you want to determine how many times the most entered element is entered.
here is some inputs and outputs
input 224455333
output 3
input 55322212266666
output 5
Dec 26 '07 #1
5 7532
Kefuci
5
I forgot to say that the array is only composed of integers.
Dec 26 '07 #2
oler1s
671 Expert 512MB
You forgot another key piece of information: your professor/teacher's e-mail address. Hey, if you're so lazy to do the work yourself, might as well tell us who to send the work to and save yourself even more trouble ;p
Dec 26 '07 #3
Kefuci
5
You forgot another key piece of information: your professor/teacher's e-mail address. Hey, if you're so lazy to do the work yourself, might as well tell us who to send the work to and save yourself even more trouble ;p
Actually I'm not lazy.I have been trying to find out the answer for 2 hours.Here is the last step I've come:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main ()
  3. {
  4.    int x[20],a,i,t,n=0,p;
  5.    for (a=0;a<=19;a++)
  6.    {
  7.       scanf ("%d",&x[a]);
  8.       if (x[a]==-1) 
  9.          break; 
  10.       i++; 
  11.    }
  12.    for(t=0;t<=i-1;t++)
  13.    {
  14.       x[t];
  15.    }
  16.    for(p=0;p<=i-1;p++)
  17.    {
  18.       x[p]; 
  19.       if (x[p]=x[t])
  20.          n=n+1;
  21.    }
  22.    printf("%d",n);
  23.    return 0;
  24. }
I'm repeating again I'm not lazy and I just need some help.The midterm is approaching and I dont have enough time.Moreover, watch your reply which seems like an accusation.
Dec 26 '07 #4
oler1s
671 Expert 512MB
Nice code. You forgot to use CODE tags around it though (formatted code is important enough that this forum has made it a rule.)

You dumped a bunch of unformatted code here, and your assignment. Well done. Now was there a question you had?

The midterm is approaching and I dont have enough time.
Sorry to hear that. Hope you finish the assignment on time.

Moreover, watch your reply which seems like an accusation.
Seems like? Definitely was.

If you had worked on code already, your first post would have had the following information: language you wanted to use, the code you already had written, OS, compiler. Then you would have stated what problem you were facing in writing your code, noting what you expected, and what you actually observed. You would have then told us how you tried to resolve this problem, and how they failed.

Your thread title is poorly named, and you have been holding back key information. If you are wondering why you are getting this kind of a response, you need to read http://www.catb.org/~esr/faqs/smart-questions.html. Seriously, read that.

As much as we're willing to help, we hold firmly to the idea of "assist" not "do someone else's work for them".
Dec 27 '07 #5
sicarie
4,677 Expert Mod 4TB
You have three for statements, one after another. Did you try to create an algorithm for this first? How would you write down all the steps so that even a small child could read your instructions and do this? That's your algorithm. From there, you can create pseudocode, and your code form that.
Dec 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
1
by: Howard Jess | last post by:
Apparently, form elements of type <input type="image" src="...> are not included in the form's elements collection. I don't understand why not; according to DOM2, all form control elements...
4
by: WindAndWaves | last post by:
Hi Gurus I have the following statement in my code: var e = form.elements; Is it possible to put any conditions on this statement. What I actually want to say is: var e = form.elements...
9
by: Luke Wu | last post by:
Hello, I'm having some problems understanding 2 dimensional arrays. My problem relates to the following code: #include <stdio.h> #define M 3 #define N 3
5
by: jtougas | last post by:
What is the way to the type of an array's elements? Array a = new long { 1, 2, 3 }; Type t = a.GetType(); Console.WriteLine( t.FullName ); This will write "System.Int64", but is not what I'm...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
3
by: Areric | last post by:
Hey all, Anyone have any idea what im doing wrong here: $image = new Image(); $image->SetImageContent($imageRow); $image->SetFileSize($imageRow); $image->SetFileName($imageRow);...
14
by: rocketman768 | last post by:
Man, that title should be in a poem, but anyways...So, I have this program, and it has an array of 40 million elements. The problem is that I have a for loop that continually is doing stuff to this...
34
by: Luke | last post by:
Hi! I am new to PHP but I am a very experienced in Perl/CGI/templates. I work in medical informatics when we deal with very large data collection forms. Some of them have over 1000 elements!...
7
by: Christof Warlich | last post by:
Hi, the subject says it all: I need to instantiate an array of objects where each object "knows" its arrary index. So far, this is easy as long as index is not a compile-time constant: class ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.