Since you present a working solution you deserve to receive some more elegant alternatives. Here is how I improved your code , there are some nice tricks for you to learn from it
#include
#define SIZE 15
int main()
{
int num[SIZE], i=0 , max;
int count = 0; // be sure that we do not read more than 15 elements
printf("Enter your integers seperated by Enter (give 0 to finish input): \n");
/*
scanf(" %d", &num[i]);
while (num[i]!=0 && count < SIZE )
{
++count;
scanf(" %d", &num[++i]);
}
*/
/* Either the above while loop */
do{
scanf(" %d", &num[i]);
count++;
} while(num[i++]!=0 && count < SIZE);
/* Or the above do { } while loop */
max = num[0]; /* Avoid to altert any of your array elements */
for(i=1; i< count; i++)
if(max < num[i]) max = num[i]; /* each time we find a better max, update our max value */
printf("%d is the greatest of them all !\n", max);
return 0;
}
I have deliberately put a smaller array of 15 elements so you can test what happens if you really try to input more than 15 elements. And if you are more lazy , you can even change it to 7 elements , you only have to go to one place and do your modification now , SIZE ! Also , comment the do-while block and uncomment the while block , and compile and run again the program with various values (pay attention to provide the max at the 1st and last positions at many of your tests) . Modify everything that you do not understand ehy it is like it is [for example change the pre-increments ++i and ++count that I use , with post-increments i++ , count++ , and compile/run/test with edge cases (max given at 1st and last positions) to see what wrong things happen ].