int n;
int *a, *b;
scanf("%d", &n);
a = (int *)malloc(sizeof(int)*n);
b = (int *)malloc(sizeof(int)*(n-1));
for (int i = 0; i < n; i++)scanf("%d", &a[i]);
for (int i = 1; i < n; i++) {
b[i - 1] = a[i] / a[i-1];
printf("%d,", b[i - 1]);
if (i%3 == 0)printf("\n");
}
free(a);
free(b);
追问额……因为才刚刚学c语言,有没有简单一点的??
追答这哪里看不懂
int n; //变量定义
int *a, *b;//变量定义
scanf("%d", &n);//读取n的值
a = (int *)malloc(sizeof(int)*n);//给指针a申请内存 长度为n
b = (int *)malloc(sizeof(int)*(n-1));//给指针b申请内存 长度为n-1
for (int i = 0; i < n; i++)scanf("%d", &a[i]);//从按键读n个数,送给a
for (int i = 1; i < n; i++) {//n-1次循环
b[i - 1] = a[i] / a[i-1];//把后项除以前项,并取整送给b
printf("%d,", b[i - 1]);//打印出来
if (i%3 == 0)printf("\n");//三个换行
}
free(a);//释放内存
free(b);//释放内存
追问好像还么有学释放内存……不过是看懂了的谢谢你!!