# Thread: Min Max Sum Average median and Mode from an Array....Where to start...Lost

1. ## Min Max Sum Average median and Mode from an Array....Where to start...Lost

I am very new to C and am needing help getting started with this code, I am needing to find the min max sum average median and mode from the array that ranges from 10 to 50 of 1000 size array. Any help is appreciated...Thanks in advance.
Code:
```#include <stdio.h>#include <stdlib.h>

int main ()
{
int mainArray[1000];
int size = 1000;
int currPos = 0;
int randNumber = 0;
srand(20);

for (currPos = 0; currPos < 1000; currPos++)
{

randNumber = rand()%41 + 10; //mix up current positions

}

}```

2. Well first of all you don't have any data in your array. Start by reading some data in.
Secondly, what is the point of using an array of size 1000 if you are only using 41 elements?
Thirdly, what are you doing using rand, what does that have to do with anything?
Lastly, main returns an int, as you yourself have written in your code, so return 0 at the end.

3. I thought that the randNumber command is filling the array. we were instructed to fill the array with random numbers from 10 to 50 and the array size to be 1000

4. Notice that you are assigning to randNumber, not to any element in mainArray.

5. Originally Posted by laserlight
Notice that you are assigning to randNumber, not to any element in mainArray.

Is this a step in the right direction?
Code:
```#include <stdio.h>#include <stdlib.h>

int main ()
{
int mainArray[1000];
int size = 1000;
int currPos = 0;
int randNumber = 0;
srand(20);

for (currPos = 0; currPos < 1000; currPos++)
{
mainArray[currPos] = rand()%50

return 0;

}```

6. Yes, it is. I suggest that you get it to compile first, and then start with finding the min.

7. Originally Posted by laserlight
Yes, it is. I suggest that you get it to compile first, and then start with finding the min.
It runs with no errors but doesnt print anything....

Code:
```#include <stdio.h>#include <stdlib.h>

main ()
{
int mainArray[1000];
int size = 1000;
int currPos = 0;
int randNumber = 0;
srand(20);

for (currPos = 0; currPos < 1000; currPos++)
{
mainArray[currPos] = rand()%50;

return 0;

int minimum, location = 1;

minimum = mainArray[10];

for (currPos = 10; currPos < 50; currPos++)
{
if (mainArray[currPos] < minimum )
{
minimum = mainArray[currPos];
location = currPos+1;
}
}
printf("Minimum element is present at location number %d and it's value is %d.\n", location, minimum);
return 0;
}
}```

8. Haha what a joke. I suggest you drop the class mate, or stop writing random crap with no understanding hoping that it will somehow magically work.

9. nevermind on why it isnt printing anything. But it always prints location 1 and the value as 0. Is the array actually being filled with numbers between 10 and 50?

10. Oh, it prints does it now? It must be printing in Hogwarts right after that return 0 you have in the middle of the code staring at you like a rapist.

11. djay86: I presume that you are a classmate of djay86753 and chose your username as a prank of sorts, but whatever, I shall assume that the both of you are different entities, so kindly stop bickering. The irrelevant posts in this thread shall be deleted.

Originally Posted by djay86
Is the array actually being filled with numbers between 10 and 50?
Print each element of the array to find out.

12. Hello,

-Assign each element of this array yourself.
-Try to find the minimum, use
Code:
`printf`
in each step to see what's going on and if what you're righting follows your thinking..

For example, finding the minimum would look like :

Code:
```#include<stdio.h>

int main(int argc, char *argv[])

{

int mainArray[5] = {10, 24, 2, 121, 0};
int i, min = 0;

for(i = 0; i<=4; i++)
{
printf("mainArray[%d] = %d\n", i, mainArray[i]);
}

printf("\n");

i = 0;

min = mainArray[i];

for(i = 0; i<=4; i++)
{

if(min > mainArray[i]) min = mainArray[i];
printf("Minimum for i=%d :%d\n", i,min);

}

printf("\nYour final Minimum is %d\n", min);

return 0;

}```
It's a good idea not to put all the "features" all in once. Put one, make it work, debug. Add the other, etc...

All my best

13. If you use a constant to define the array size, and use it for all your array loops, then you can use Jugurtha's solution to make your program work, and simply change the constant definition to 1000, and your assignment will be done. Literally changing just a few characters.

14. i don't know why some 'nerds' tend to be arrogant to other dudes.....

15. @OP: Do you know what
Code:
`return 0;`
does? Not sure if it's an accident or you truly don't know its function, but because you left it in, your main function returns before it even gets to the sorting part.

Also, it's technically included in the for loop, because the extra brace at the bottom makes it compile correctly, but it definitely won't function correctly. How you have it now, it's filling one number, doing the sort, filling another, doing the sort, etc.

Code:
`minimum = mainArray[10];`
What? Why not just make it equal to zero, instead of picking a random array index that very well might be the largest value in the array. You're making the same mistake on the sorting loop. Do you even understand how loops and arrays work?

Originally Posted by Nyah Check
i don't know why some 'nerds' tend to be arrogant to other dudes.....
What the ........ are you talking about? No offense, but a lot of your replies are completely irrelevant, dumb, and/or re-stating what's been said.