![]() |
|
#1
|
|||
|
|||
float arrays questionI am having problems writing this code. I have to write a program that declares a float array with 100 elements and also:
1. displays the sum of the elements in the array 2. displays the smallest number in the array 3. displays the 5 largest numbers in the array If anyone could provide me with a little (or a lot) of help I would appreciate it! Please... This is the beginning that I have so far... CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
|
OK...I have created a program but it does not do what I want it to do..I am only able to find the greatest of three numbers...how do I get five?
Here is what I have since my last post... CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
|
Quote:
I don't understand your declarations for int x. You want float x[100]. I'll get you started: First of all in order to test the code, you have to put something into the array. I will fill the array with random numbers between 0 and 1. Maybe you want some other function to put some values in the array, since with random values, how will you know you have the right answer? For example you could simply set ary[i] = (float)i in your fill_array() function. Whatever. Here's a thought: start with an array, say of 10 elements and initialize it with some specific values. Then print out all of the values, and see if your functions are working properly on them. Just a thought. Here's a start: CPP / C++ / C Code:
Now, you must make functions that step through the array that 1. add the elements and return the value in function sum_array(). 2. find the smallest element in the array and return its value in function smallest_in_array(). 3. find the smallest five elements and return them somehow. Do the first two things and save this for last. Regards, Dave |
|
#4
|
|||
|
|||
|
Quote:
I see what you are saying Dave...but I really don't understand how to get 100 or even 10 elements to output randomly. I know that I have to use srand but how do I format it? By the way...thank you for replying to my message. |
|
#5
|
|||
|
|||
|
Quote:
CPP / C++ / C Code:
change this CPP / C++ / C Code:
to something like this CPP / C++ / C Code:
Now, it's your turn. Regards, Dave |
|
#6
|
|||
|
|||
|
OK...this generates 100 random numbers...but chooses the second largest. How do I make it choose the 5 largest?
CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
|
Following is one way to find 5 largest numbers in set of 100 numbers.
CPP / C++ / C Code:
This is just one way. Someone might come up with more efficient way to do it. |
Recent GIDBlog
Toyota - 2008 September Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I was wondering.... | n3pla | Computer Software Forum - Windows | 1 | 28-Jul-2002 04:33 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The