学习是进步的基础.
//程序如下: #include <stdio.h> #include <stdlib.h>
void fuzhiarry() { int arrynum; int counterip = 0; int counterarry = 0; int * iarry; int * ip; printf("please input the arry length : \n"); scanf("%d", & arrynum); iarry = (int *)malloc(arrynum *sizeof(int)); if(!iarry) exit(1); for(int i = 0 ; i < arrynum; i++) { printf("please input the %dth result\n", i+1); scanf("%d",iarry); iarry++; } iarry -= arrynum; ip = (int * )malloc(arrynum * sizeof(int)); if(!ip) exit(1); do { if(*iarry && counterarry < arrynum ) { *ip = *iarry; ip++; iarry++; counterip++; counterarry++; } else { counterarry++; iarry++; } }while(counterarry < arrynum);
ip = ip - counterip; iarry = iarry - arrynum; for(int j = 0;j<arrynum;j++) { printf("\n"); printf("输入数组的第 %d 数为:\n",j+1); printf("%-5d",*iarry); iarry++; } printf("\n"); for(int k = 0 ;k<counterip;k++) { printf("\n"); printf("转换数组的第 %d 数为:\n", k+1); printf("%-5d",*ip); ip++; } printf("\n"); ip -= counterip; iarry -= arrynum; free(ip); free(iarry); } void main() { fuzhiarry(); }