6 coding best practices for beginner programmers (original) (raw)
#include <stdio.h>
/**
Finds the largest integer from the given array (inputAry)
of size (inputArySize).
*/
int findLargest(int inputAry[], int inputArySize) {
//Assumption: array will have +ve elements.
//Thus, the largest is initialized with -1 (smallest possible value).
int largest = -1;
// Iterate through all elements of the array.
for (int loop = 0; loop < inputArySize; loop++) {
//Replace largest with element greater than it.
if (inputAry[loop] > largest) {
largest = inputAry[loop];
}
}
//returns the largest element of the array
return largest;
}
int main() {
int A[]={1, 4, 7, 13, 99, 0, 8, 5};
printf("\n\n\t%d\n\n", findLargest(A, 8));
return 0;
}