#include <stdio.h>
/*************************************************/
/* 函数名: main()
*/
/* 功能:
擦出一个数组中重复的元素
*/
/*************************************************/
main()
{
char data_ram, number_tab[100];
unsigned char number_counter=0, counter1=0, counter2=0, cal_ram=0;
unsigned char counter3=0;
printf("Please input your number(-1 to end)\n");
scanf("%d", &data_ram);
while ( data_ram!=-1 )
{
number_tab[number_counter] = data_ram;
++number_counter;
scanf("%d", &data_ram);
}
/*输入要处理的正整数数组*/
--number_counter;
printf("The number you input is:\n");
for ( counter1=0; counter1<=number_counter; ++counter1)
{
printf("%d\t", number_tab[counter1]);
}
printf("\n");
/*打印用户输入的正整数数组*/
for ( counter1=0; counter1<number_counter; ++counter1)
{
for ( counter2=counter1+1; counter2<=number_counter; ++counter2 )
{
if ( number_tab[counter1]==number_tab[counter2] )
{
for ( counter3=counter2; counter3<number_counter; ++counter3 )
{
number_tab[counter3]=number_tab[counter3+1];
}
--counter2;
--number_counter;
}
}
}
/*擦除数组中重复的元素*/
printf("Processed number is:\n");
for ( counter1=0; counter1<=number_counter; )
{
for ( counter2=0; counter2<3; ++counter2)
{
printf("%d\t", number_tab[counter1]);
if ( ++counter1>number_counter )
{
break;
}
}
printf("\n");
}
/*打印处理后的数据*/
}
以测试完毕。 用户可以随意输入一个正整数数组 运行结果擦出数组中的重复元素
[
本帖最后由 小白来学习 于 2010-10-30 09:38 编辑 ]