gpt4 book ai didi

c - 不允许输入第一个值的打印功能

转载 作者:太空宇宙 更新时间:2023-11-04 07:59:38 24 4
gpt4 key购买 nike

<分区>

我在运行代码时无法从键盘输入值。一切都编译成功,但是当我去运行我的代码时,它打印出来是这样的:

How many numbers would you like to place in the array: 7
Enter number 1: Enter number 2:

等等等等

为什么会这样?另外,有没有办法统计和存储每个元素在数组中出现的次数?

int main(void)
{

int numbers = 0;
int j = 0;
char numStorage[j];
int times = 0;
char newArray[j];

printf("How many numbers would you like to place in the array: ");
scanf("%d", &numbers);

j = numbers;

int i = 1;

while (i < (numbers + 1))
{
printf("Enter number %d: ", i);
scanf("%c", &numStorage[i]);
i++;
}//close of while loop

int x;

for (x = 0; x < numbers; x++)
{
newArray[x] = numStorage[x];
}//close of for loop

int z;
int q;

for (z = 0; z < numbers; z++)
{
for (q = 0; q < numbers; q++)
{
if (numStorage[z] == numStorage[q])
{
times++;
q++;
}//close of if
else
{
q++;
}//close of else
}//close of for loop

printf("\n%d occurs %d times", numStorage[z], times);
z++;
q = 0;
times = 0;
}//close of for loop

}//end of main method

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com