In C Write a method to compute and return the value of max m

In C, Write a method to compute and return the value of max- min where max is the largest element of an int array and min is the smallest element of an int array. The method is passed the int array and int value that denotes the number of elements in the array, assuming the int array having atleast one element in it.
In C, Write a method to compute and return the value of max- min where max is the largest element of an int array and min is the smallest element of an int array. The method is passed the int array and int value that denotes the number of elements in the array, assuming the int array having atleast one element in it.

Solution

Solution.c

#include <stdio.h>//header file for input output function

int find_min_max(int[], int); //function declaration

int main() {//main function
int c, array[100], size, location, minimum;//variable declaration

printf(\"Input number of elements in array :\");
scanf(\"%d\", &size);//key board inputting

printf(\"Input %d integers :\ \", size);

for (c = 0; c < size; c++)
    scanf(\"%d\", &array[c]);//key board inputting

find_min_max(array, size);



return 0;
}

int find_min_max(int a[], int n) {//function definition
int min, index1,max,index2;//variable declaration

min = a[0];//variable assignment
max=a[0];
index1 = 0;
index2=0;

for (int i = 0; i < n; i++) {//logic for minimum element
    if (a[i] < min) {
       index1 = i;
       min = a[i];
    }
}
printf(\"minimum element is %d\ \",min);
for (int j = 0; j < n; j++) {//logic for maximum element
    if (a[j] > max) {
       index2 = j;
       max = a[j];
    }
}
printf(\"maximum element is %d\",max);

return 0;
}

output

56                                                                                                                                                                       

67                                                                                                                                                                       

78                                                                                                                                                                       

67                                                                                                                                                                       

minimum element is 45                                                                                                                                                    

maximum element is 78sh-4.3$ gcc -o main *.c                                                                                                                             

sh-4.3$ main                                                                                                                                                             

Input number of elements in array :5                                                                                                                                     

Input 5 integers :                                                                                                                                                       

34                                                                                                                                                                       

23                                                                                                                                                                       

1                                                                                                                                                                        

-78                                                                                                                                                                      

67                                                                                                                                                                       

minimum element is -78                                                                                                                                                   

maximum element is 67

In C, Write a method to compute and return the value of max- min where max is the largest element of an int array and min is the smallest element of an int arra
In C, Write a method to compute and return the value of max- min where max is the largest element of an int array and min is the smallest element of an int arra

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site