// Original] how to remove repeated elements from Arrays
//
# Include <stdio. h>
Int main ()
{
Int a [5];
Printf ("input five numbers :");
For (int I = 0; I <5; I ++)
{
Scanf ("% d", & a [I]);
}
Int len = 5; // 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 (int n = 0; n <len; ++ n)
{
Printf ("% d", a [n]);
}
Printf ("\ n ");
Return 0;
}
This article is from the "Jean_Z learning blog" blog, please be sure to keep this source http://7905490.blog.51cto.com/7895490/1296747