Given n numbers, find maximum difference between some two of them. For example, for input data 1 2 7 -6 we have 13=7-(-6). But my code doesn't seem output correct results:
#include <iostream>
#include <algorithm>
int main()
{
int n, j, k;
std::cin >> n;
int *a;
a = new int[n];
for (j=0; j<n; j++)
{
std::cin >> a[j];
}
std::sort(a, a + sizeof(int));
k=a[n-1]-a[0];
std::cout << k;
delete [] a;
return 0;
}