当涉及到C语言并插入到数组中时,我完全卡住了。我有我的代码在下面,并解释说,用户想要一个数组3.所以用户输入4 3 2到数组a1[n]
。我需要数组a2[]
输出相同的数字,但每个之间为零。当输出a2[]
时,最终结果将为4 0 3 0 2 0。我将如何在每个其他元素之间得到一个零?在我的数组中的每个元素之间插入一个数字C
#include <stdio.h>
int main() {
int n = 0;
int number = 0;
int a1[n];
int a2[2 * n];
printf("Enter the length of the array: ");
scanf("%d", &n);
printf("Enter the elements of the array: ");
for(i = 0; i < n; i++){ //adds values to first array
scanf("%d",&number);
a1[i] = number; }
for(i = 0; i < n; i++){ //copies and sets the arrays the same
a2[i] = a1[i]; }
是否一定有一个与那些零数组?您可以在输出数组时直接插入它们。 – LibertyPaul
不,这不是必要的,但会帮助我学习任何一种方式 – user6124417