I want to write a code where will be given n integer numbers.The program will print the two numbers whose difference is the closest.It will show any two, if there are many numbers giving the same minimum difference.
I wrote a code but I don't get the desired result.Would you give me some help? :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main ()
{
int n,max,num,difference;
cin >> n >> max;
for (int i=1;i<=n-1;i++)
{
cin >> num;
if (num>max) {max=num;
difference=num-max;
}
cout << max << " " << num << " " << difference;
return 0;
}
}