gpt4 book ai didi

c - 将结果读入c中的数组

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

只是想知道我在这里做错了什么?这是非常简单的编程,我真的应该知道这一点,但就是看不到问题所在! Scanf 不会将方程式的结果读入数组中的相应位置。

#include <stdio.h>

int main(void)
{
int numbers[4];

printf("Please enter 2 numbers:\n");
scanf("%d %d", &numbers[0], &numbers[1]);

printf("Your 2 numbers added are: %d\n", numbers[0] + numbers[1]);
scanf("%d", &numbers[2]);

printf("Your 2 numbers subtracted are: %d\n", numbers[0] - numbers[1]);
scanf("%d", &numbers[3]);

printf("The results of your program are: %d, %d\n", &numbers[2], &numbers[3]);

return 0;
}

最佳答案

    #include <stdio.h>

int main(void)
{
int numbers[4];

printf("Please enter 2 numbers:\n");
scanf("%d %d", &numbers[0], &numbers[1]);

printf("Your 2 numbers added are: %d\n", numbers[0] + numbers[1]);
numbers[2] = numbers[0] + numbers[1];

printf("Your 2 numbers subtracted are: %d\n", numbers[0] - numbers[1]);
numbers[3] = numbers[0] - numbers[1];

printf("The results of your program are: %d, %d\n", numbers[2], numbers[3]);

return 0;
}

试试这个..

关于c - 将结果读入c中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8712003/

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