Write a subroutine that finds the maximum number in an array
Write a subroutine that finds the maximum number in an array. The array contains 8-bit signed numbers. The first element of the array is the size. Register R0 is a call by reference pointer to the array. The maximum value in the array is returned in Register R0.
Solution
Code:
#include <stdio.h>
main(){
int array[100], *maximum, size, c, location = 1;
printf(\"Enter the number of elements in array\ \");
scanf(\"%d\",&size);
printf(\"Enter %d integers\ \", size);
for ( c = 0 ; c < size ; c++ ){
scanf(\"%d\", &array[c]);
}
maximum = array;
*maximum = *array;
for ( c = 1 ; c < size ; c++ ){
if ( *(array+c) > *maximum ){
*maximum = *(array+c);
location = c+1;
}
}
printf(\"maximum element is %d\", *maximum);
return 0;
}
Output:
