//从键盘对一个有十个元素的数组任意赋值,并将相同的数删得只剩一个! #include <stdio.h>
void only_arry(int a[],int n); void select_arry(int a[],int n);
void only_arry(int a[],int n) { int i; int j; int ip; int counter; char temp[10]; counter=0; ip=0; for(i=0;i<n;) { temp[ip++]=a[i]; for(j=i+1;j<n;j++) { if(a[j]==a[i]) ++counter; else break; } i+=counter+1; counter=0; } printf("the final arry as following:\n"); for(i=0;i<ip;i++) printf("%5d",temp[i]); printf("\n");
}
void select_arry(int a[],int n) { int i; int j; int k; int temp; for(i=0;i<n;i++) { k=i; for(j=i+1;j<n;j++) { if(a[j]<a[k]) k=j; } if(k!=i) { temp=a[k]; a[k]=a[i]; a[i]=temp; } } }
int main() { int n; int i; int a[10]; n=10; printf("please enter the a_arry's number!\n"); for(i=0;i<n;i++) { printf("please enter the%d arry's number:\n",i+1); scanf("%d",&a[i]); } select_arry(a,n); only_arry(a,n); return 0; }