Hi everyone, this is my first post on this forum. I've been browsing these boards for awhile and thought it would be a good idea to register now, for i hope someone can help me out :)
I've created a program which enables a user to input numbers from 1 to 10. First it asks for the user to specify the amount of numbers that are going to be put in. Then the numbers are inserted and stored in an array.
After that a frequency array get's made from the user's input and a histogram gets printed. So far, so easy :)
Here's the code for my program:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int numberRow[100];
int frequenties[11];
int numbers, loopNumber = 0;
scanf("%d", &numbers);
do {
scanf("%d", &numberRow[loopNumber]);
loopNumber++;
} while (loopNumber < numbers);
int x;
for(loopNumber = 0; loopNumber<numbers; loopNumber++) {
for(x = 1; x <= 10; x++) {
if(numberRow[loopNumber]==x) {
frequencies[x]++;
}
}
}
int highestNumber = 0;
for(x=1; x<= 10; x++) {
if(frequenties[x]>highestNumber) highestNumber=frequenties[x];
}
int y;
for(x=highestNumber; x>0; x--) {
for(y=1; y<=10; y++) {
if(frequenties[y]< highestNumber && x > frequenties[y]) {
if(y==10)
printf(".");
else
printf(". ");
}
else if(frequenties[y]<= highestNumber && x <= frequenties[y]) {
if(y==10)
printf("*");
else
printf("* ");
}
}
printf("\n");
}
printf("1 2 3 4 5 6 7 8 9 10\n");
return 0;
}
Resulting in the following output, given the input:
[IMG]http://i36.tinypic.com/2chgn8.png[/IMG]
However, now i'm asked to make the same program, but from unfinished source-code:
#include <stdio.h>
#include <stdlib.h>
int *readNumbers() {
int *numbers;
/* To-Do: implement body */
return numbers;
}
void getFrequency(int numbers[], int freq[11]) {
/* To-Do: implement body */
}
int arrayMax(int length, int row[]) {
int i;
int max = row[0];
for (i=1; i<length; i++) {
if (row[i] > max) {
max = row[i];
}
}
return max;
}
void printHistogram(int frequenties[11]) {
/* To-Do: implement body */
}
int main(int argc, char *argv[]) {
int *numbers;
int frequencies[11]
numbers = readNumbers();
/* To-Do: finish the rest */
return 0;
}
I'm very confused with this 'setup', for it insists on using pointers (?) and as far as i can see the premade (but unfinished) getFrequency() and printHistogram() functions are missing an extra argument (the size of the frequency-array) in order to get a working program.
I've been looking at the code for several hours but so far i'm unable to find a way to make this same program, in that different way.
Any input will be much appreciated! :)
Cheers,
Stuart