# Thread: Finding the maximum in an array

1. ## Finding the maximum in an array

Alright, newb question, bare if you can =P, I do have an example of my work, dont worry im not asking you to do my homework. Alright, I need the user to input 10 intergers, store them in a float array and output the max, hes my work so far.

Code:
```#include<stdio.h>
#define size 10

main()
{
int i, A[size];
float max;

printf("Enter 10 intergeers: ");
for (i=0; i<size; i++)
scanf("%f", &A[i]);

for (i=0; i<size; i++){
if (A[i] > max)
max == A[i];
}

printf("The max is %.0f \n", max);

system("PAUSE");

return 0;

}```
obviously it just spits out some nonsense. Not sure what im doing wrong. Thanks for any help.

2. Code:
```int i, A[size];
scanf("%f", &A[i]);```
Use %d or %i to read in ints. %f is for floats. [edit=3] Actually, since you made max a float, you might want to make A a float too instead. In that case you would leave the %f alone.

In future, you can look up the scanf() function if you suspect that something's wrong with it. http://www.cppreference.com/stdio/scanf.html [/edit]

Code:
`max == A[i];`
Your compiler might warn you about this if you turned on warnings (and the %f vs %d too). You meant to use a single '=' for assignment. [/edit]

[edit=2]
Code:
`main()`
You should use int main() for new programs.
Code:
`int main()`
or
Code:
`int main(void)`
http://faq.cprogramming.com/cgi-bin/...&id=1043284376 [/edit]

3. Code:
`system("PAUSE");`
to just pause the process system() is not a good idea cos it takes much of OS time to process it. Its better to use a getchar which is nothing but waitng till a char on a key board is entered which seems like it is been paused

`getchar();`