ARRAYS

Published on
Embed video
Share video
Ask about this video

Scene 1 (0s)

ARRAYS. -1 D Array.

Scene 2 (29s)

What is an Array?. An array is a variable that can store multiple values of same data type..

Scene 3 (2m 18s)

How do we Declare an Array?. The general form of declaring a one dimensional array is: data-type array-name[size];.

Scene 4 (3m 24s)

How do we access the elements in an Array?. An array element is accessed by its index. array-name[index];.

Scene 5 (4m 8s)

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..

Scene 6 (4m 54s)

Problem Statement. Question: Write a C program to find the sum of the maximum and minimum numbers of an unsorted array..

Scene 7 (5m 28s)

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);.

Scene 8 (6m 28s)

Flowchart:. Start. Read ‘n’. Read the elements of ‘arr’.

Scene 9 (7m 17s)

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]);.

Scene 10 (8m 11s)

Compare each and every element with max and min and update the values:.

Scene 11 (8m 39s)

Source Code:. #include <stdio.h> int main(){. int n, arr[100], i,max,min,Sum;.

Scene 12 (9m 10s)

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.

Scene 13 (9m 50s)

THANK YOU.