// Original] C language, how does an array calculate the maximum value and secondary limit after removing repeated elements?
# Include <stdio. h>
Int main ()
{
Int a [7];
Printf ("input seven numbers :");
For (int I = 0; I <7; I ++)
{
Scanf ("% d", & a [I]);
}
Int len = 7; // 5 5 5 2 5
// Two for loops are used to traverse
For (int j = 0; j <len; ++ j)
{
For (int m = j + 1; m <len; ++ m)
{
If (a [j] = a [m])
{
// Use the overwrite method to delete the same element as the first for statement.
For (int k = m + 1; k <len; ++ k) // there will be differences in writing-According to k = m + 1, may be a len-1 or other...
A [k-1] = a [k];
Len --; // keep up with the length
-- M; // because an element is deleted, the subscript of the array element to be compared with a [j] does not change but the value has changed)
}
}
}
For (I = 0; I <len; I ++)
Printf ("% d", a [I]);
Printf ("\ n ");
Int temp;
For (int n = 0; n <len; n ++)
For (int p = n + 1; p <len; p ++)
If (a [n] <= a [p])
{
Temp = a [n];
A [n] = a [p];
A [p] = temp;
}
For (I = 0; I <len; I ++)
Printf ("% d", a [I]);
Printf ("MAX = % d, S_MAX = % d \ n", a [0], a [1]);
Return 0;
}
// Running result
// Input seven numbers: 7 5 7 5 8 6 8
// 7 5 8 6
// 8 7 6 5 MAX = 8, S_MAX = 7
// Press any key to continue
This article is from the "Jean_Z learning blog" blog, please be sure to keep this source http://7905490.blog.51cto.com/7895490/1299815