ARRAYS. -1 D Array.
What is an Array?. An array is a variable that can store multiple values of same data type..
How do we Declare an Array?. The general form of declaring a one dimensional array is: data-type array-name[size];.
How do we access the elements in an Array?. An array element is accessed by its index. array-name[index];.
How can we find maximum and minimum elements?. If the number is greater than all other elements of an array, then we can say it is a maximum element we can find this using ‘>’ operator we can find the maximum element. If the number is smaller than all other elements of an array, then we can say it is a minimum element we can find this using ‘<’ operator we can find the minimum element..
Problem Statement. Question: Write a C program to find the sum of the maximum and minimum numbers of an unsorted array..
Algorithm:. Read n 9. Exit Repeat step 3 for i=0 to n-1 Read arr[i] [End of step 2 loop] [Initialization of maximum and minimum variables] max = arr[0] , min = arr[0] Repeat step 6 for i=0 to n-1 if arr[i] > max then, max=arr[i] end if if arr[i] < min then, min=arr[i] end if [End of step 5 loop] 7. sum=max+min 8. print the sum of max and min values printf(“ The sum of maximum and minimum elements of an array is:”+sum);.
Flowchart:. Start. Read ‘n’. Read the elements of ‘arr’.
Program Building:. Reading the elements of an array: Let’s say n=5; //Code to read 5 elements of an array scanf(“%d”,&arr[0]); scanf(“%d”,&arr[1]); scanf(“%d”,&arr[2]); scanf(“%d”,&arr[3]); scanf(“%d”,&arr[4]);.
Compare each and every element with max and min and update the values:.
Source Code:. #include <stdio.h> int main(){. int n, arr[100], i,max,min,Sum;.
Output:. Test case 1: Enter the size of the array :5 Enter the elements of the array : 8 5 9 2 6 Sum of maximum and minimum elements is : 11.
THANK YOU.