Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Please help with writing this simple prog.

Posted on 1998-11-05
3
Medium Priority
?
167 Views
Last Modified: 2010-04-15
I have a file which contain lots of numbers. I want to find the frequancy of each range.Can somebody help me with the strategy to write this program.
-the file contain numbers say 1-1000 so the min and max are known in advance
-the user input the width eg. 10 so there should be 1000/10 =100 number of classes (width=user input variable)
the program should search and find the frequency between numbers b/w 0-199, 200-299, 300-399 until 1000. So the result should be
class       Lower limit    upper limit  frequency      Prop
0           0.000           199.000      120          0.0987

thanks alot for you help
0
Comment
Question by:Paris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 400 total points
ID: 1254060
I would approach it with arrays. The overall range of the numbers is 1 - 1000. Get the width from the user. If he enters 10 there will be 100 classes (which would be 0 - 9, 10 - 19 etc), if he enters 100 there will be 10 (0 - 99, 100 - 199 etc.). In general then the number of classes will be 1000/width. (Or you could ask them to enter the number of classes they want, and deduce the "width" instead).

Once you have the number of classes allocate an array of that length using malloc or calloc:

int *class;

class=calloc(classnum,sizeof(int));

Then read through the file and increment the appropriate class for each number:

/* num is number from file */
++class[num/classnum];

When you have processed all the number the frequency will be contained in each array element and each class can be conceptually printed as:

/* i is the class number */

class i:
Lower limit  i*width
Upper limit  (i+1)*width-1
frequency class[i]

I'm not sure what the Prop  represents.

0
 
LVL 16

Expert Comment

by:imladris
ID: 1254061
P.S. note that if the range is in fact 1 - 1000 (as opposed to 0 - 999) you will have to account for 1000 appearing. As it stands ++class[1000/width] would address an element one past the end of the array. You could check, and force it into the last element instead, or allocate one extra element, or subtract 1 from all the numbers (thus converting it from 1 - 1000 to 0 - 999). It will be easy to handle, as long as you're aware of the issue.

0
 

Author Comment

by:Paris
ID: 1254062
I 'll try it and get back to you. Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question