回复 楼主 billjyc
#include <stdio.h>
#define
N 2
#define
M 3
#define
K
N * M
#define
STRING
" element
times \n "
int main( )
{
void arr_conv(int array[][M], int a2[K]);
void elem_count(int array[K]);
int
a1[N][M], a2[K];
int
i, j;
while (888)
{
printf("Please input a
two-dimensional array:");
for (i = 0; i < N; i++)
for (j = 0; j < M; j++)
scanf("%d", &a1[i][j]);
printf("\nNow original array a1[N][M] is :\n");
for (i = 0; i < N; i++)
{
for (j = 0; j < M; j++)
printf("%-6d ", a1[i][j]);
printf("\n");
}
arr_conv(a1,a2);
elem_count(a2);
}
return 0;
}
void
arr_conv(int array[][M], int a2[K])
{
int i , j ;
for (i = 0; i < N; i++)
{
for (j = 0; j < M; j++)
a2[i * M + j] = array[i][j];
}
printf("a2[K] = {");
for(i =
0; i < K - 1; i++)
printf("%d,", a2[i]);
printf("%d}.\n", a2[K - 1]);
}
void elem_count( int array[K] )
{
int i , j, n , m = 0, len = K, s ,a3[K];
for (i = 0; i < len; i++)
{
for ( j = i + 1 , n = 0 ; j < len; j++)
if (array[i] == array[j])
{
for (s = j; s < len ; s++)
array[s] = array[s + 1];
// Delete the same number
len--;
j--;
n++;
a3[i] = n;
}
if (m < n)
m = n;
printf(STRING);
printf("%6d
----->
%d\n", array[i], n + 1 );
}
for (i = 0; i < len; i++)
{
if (a3[i] == m)
printf("Element %d appeared mostly, it appeared %d times.\n", array[i], m + 1);
}
}
[
本帖最后由 有容就大 于 2011-12-18 01:28 编辑 ]