Code:
if (arr[i]>max) {
max=arr;
subscript = i;
}
heh - forgot to add the braces to make it into a block (So much for actually checking if the code works on the compiler)
edit:
Perhaps this suits you - take a look at what I changed with regards to the use of 'largest' (What you called 'max'):
Code:
#include <stdio.h>
#include <string.h>
#include <limits.h>
#define MAX_NUMBER 20
int main(void)
{
int arr[MAX_NUMBER];
int largest = INT_MIN; /* used to be 'max' */
int subscript;
int i;
for (i = 0; i < MAX_NUMBER; i++) {
printf("Enter a number: ");
scanf("%d", &arr[i]);
if (arr[i] > largest) {
largest = arr[i];
subscript = i;
}
}
printf("Largest entry is %d and is found at arr[%d]\n", largest,
subscript);
return 0;
}
As well, I cleaned up some of your 'magic numbers' - Generally speaking it is a good idea to use symbolic constants where possible. In the above example, if I want to change the amount of numbers from 20 to 10, I need only change one line:
Code:
#define MAX_NUMBER 20
The way it was before there would have been a couple of places needing to be changed. On a small program this may little trouble (But as Kenneth Reek says, 'Little trouble is some trouble.') but on a bigger program it could be a nightmare.