Write a Program to Read in 10 Numbers and Compute the Average, Maximum and Minimum Values.

C program to find the maximum and minimum chemical element in an array – In this article, nosotros will brief in on the many ways to detect the maximum and minimum element in an array in C programming.

Suitable examples and sample programs have also been added and then that you tin empathise the whole affair very clearly. The compiler has also been added with which you can execute it yourself.

The means used in this piece are as follows:

  • Using Standard Method
  • Using Function
  • Using Recursion

Every bit we all know, arrays are a collection of a agglomeration of elements in a sequential pattern in a horizontal direction. Arrays form a very important of C programming.

C Program To Find Maximum & Minimum Element In Array

Every bit given in the example above, firstly, enter the size of the array that you desire to define.

The size of the array in the example mentioned is 5.

After that, you need to enter the elements of the assortment.

The elements entered in the assortment are equally follows:

1 ii 35 0 -ane

And so, the minimum of the array is -1 and the maximum of the array is 35.

Thus, doing the same using multiple methods in C programming is as follows:

Using Standard Method

  1. Read the entered array size and shop that value into the variable n.

ii)Read the entered elements using scanf and store the entered assortment elements into the array using for loop for(i=0;i<n;i++).

3)Initialise min, max values with the 1st chemical element of the array.

four)Compare min, max values with a[i],

If min value is greater than a[i] then initialise min=a[i] and if max value is less than a[i] then initialise max=a[i]. Repeat this step for each element of the string using for loop which is having the structure for(i=1;i<n;i++).

Print the minimum of the array and maximum of the array values.

Output:

Using Role

  1. A function is a group of statements which perform a particular job. In this plan sumofarray() is a role which finds the minimum and maximum of an array.

ii) The chief() function calls the sumofarray() function past passing an assortment, size of the assortment value every bit arguments.

iii) The function sumofarray() compares the min, max values with assortment elements and prints the minimum of array element and maximum of array element values.

Output:

Using Recursion

  1. A role which calls itself until some condition is called recursive function.

2) In this plan, we accept two recursive functions bachelor.one is minimum() and another i is maximum(). Both these functions telephone call by itself.

three) The main() function calls the minimum() past passing array,assortment size,1 as arguments.

Then the office minimum()

a) Checks the condition i<due north, If it is true

b) So it compares a[min]>a[i] if it is also true

c)And then min initialised to i and calls the role by itself by increasing i value until the status a[min]>a[i] becomes simulated. This function returns the min to the master office.

master() function prints the a[min] value of the array.

4)The master() function calls the maximum() function past passing array,array size,ane as arguments.

And then the function maximum()

a)Checks the condition i<northward, if it is truthful

b)And so it compares a[max]<a[i] if it is true

c)And so max initialise to i and calls the office itself past increasing i value until the condition a[max]<a[i] becomes false. This function returns the max to the main function.

main() function prints the a[max] value of the array.

Output:

yuegary2001.blogspot.com

Source: https://javatutoring.com/c-program-find-maximum-minimum-element-in-array/

0 Response to "Write a Program to Read in 10 Numbers and Compute the Average, Maximum and Minimum Values."

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel