Largest difference between two array elements.

C program to print the largest difference between two array elements.

Program

#include<stdio.h>
#include<conio.h>
#define MAX 50

void main()
{
	int arr[MAX];
    int i, n, max, min;

    printf("Enter the number of elements in the array\t:");
    scanf("%d",&n);
    printf("Enter the elements\n");
    for(i=0;i<n;i++)
    {
        printf("Element %d\t:",i+1);
        scanf("%d",&arr[i]);
    }

    max = arr[0];
    min = arr[0];
    for(i=0;i<n;i++)
    {
        if(arr[i] > max)
            max = arr[i];
        if(arr[i] < min)
            min = arr[i];
    }
    
    printf("\nLargest element of the array is\t:%d",max);
    printf("\nSmallest element of the array is\t:%d",min);
    printf("\nLargest difference between two array elements is\t:%d",max-min);

    getch();
}

Output

Enter the number of elements in the array       :8
Enter the elements
Element 1       :78
Element 2       :45
Element 3       :12
Element 4       :23
Element 5       :56
Element 6       :89
Element 7       :52
Element 8       :58

Largest element of the array is :89
Smallest element of the array is        :12
Largest difference between two array elements is        :77