Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
707 B
4
Indexable
Never
#include <iostream>
using namespace std;
void input(float[], int&);
float min(float[], int);
float max(float[], int);
int main()
{
	int n;
	float a[1000];
	input(a, n);
    float m = min(a, n);
    float M = max(a, n);
    float kq = M - m;
    cout << kq << endl;
	return 0;
}

void input(float a[], int& n)
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

float min(float a[], int n)
{
    float min = a[0];
    for (int i = 1; i < n; i++)
        if (a[i]<min)
            min = a[i];
    return min;
}

float max(float a[], int n)
{
    float max = a[0];
    for (int i = 1; i < n; i++)
        if (a[i]>max)
            max = a[i];
    return max;
}