Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int absolute_value(int a) {
- if(a < 0) {
- return -a;
- }
- else {
- return a;
- }
- }
- int min(int a, int b) {
- if(a < b) {
- return a;
- }
- else {
- return b;
- }
- }
- int max(int a, int b) {
- if(a > b) {
- return a;
- }
- else {
- return b;
- }
- }
- int main()
- {
- int n;
- cin >> n;
- int niza[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- }
- int najgolem = -2000000000;
- int najmal = 2000000000;
- for(int i = 0; i < n; i++) {
- najmal = min(najmal, niza[i]);
- najgolem = max(najgolem, niza[i]);
- }
- cout << absolute_value(najmal - najgolem) << endl;
- return 0;
- }
- // 5
- // 4 3 1 2 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement