Write a userdefined function definition for a function calle
Write a user-defined function definition for a function called GetLargest that takes 2 arguments: an array of integers, and the size of the array. The function should return the largest value in the array. You should not assume that the variables will contain different values.
Solution
Solution.cpp
#include <iostream>//header file for input output function
 using namespace std;// it tells the compiler to link std namespace
 int GetLargest(int[], int); //function declaration
int main() {//main function
 int c, array[100], size;//variable declaration
cout<<\"Input number of elements in array :\";
 cin>>size;//key board inputting
cout<<\"Input \"<<size<<\" integers :\ \"<< size;
for (c = 0; c < size; c++)
     cin>>array[c];//key board inputting
GetLargest(array, size);
 return 0;
 }
 int GetLargest(int a[], int n) {//function definition
 int max,index;//variable declaration
 max=a[0];
 index=0;
 for (int j = 0; j < n; j++) {//logic for maximum element
     if (a[j] > max) {
        index = j;
        max = a[j];
     }
 }
 cout<<\"maximum element is \"<<max;
return 0;
 }
 output
Input number of elements in array :5
Input 5 integers :
78
66
56
99
77
maximum element is 99
Solution.c
#include <stdio.h>//header file for input output function
int GetLargest(int[], int); //function declaration
int main() {//main function
 int c, array[100], size;//variable declaration
printf(\"Input number of elements in array :\");
 scanf(\"%d\",&size);//key board inputting
printf(\"Input %d integers :\ \");
for (c = 0; c < size; c++)
     scanf(\"%d\",&array[c]);//key board inputting
GetLargest(array, size);
 return 0;
 }
 int GetLargest(int a[], int n) {//function definition
 int max,index;//variable declaration
 max=a[0];
 index=0;
 for (int j = 0; j < n; j++) {//logic for maximum element
     if (a[j] > max) {
        index = j;
        max = a[j];
     }
 }
 printf(\"maximum element is %d \",max);
return 0;
 }
 output
Input number of elements in array :5
Input 1 integers :
45
6
77
9
77
maximum element is 77


