C 程序,用户输入到单个数组中

标签 c arrays user-interface

我正在尝试使用用户通过 CodeBlocks 在一行中输入的三个整数到一个数组中。但我真的不知道该怎么做。谁能帮我吗?

谢谢!

main()
{

    int arr[3];
    int onenum;
    int twonum;
    int threenum;
    printf("Enter an Input: ");
    scanf("%d %d %d",&onenum,&twonum,&threenum);
    printf("Your input is: %d %d %d \n",onenum,twonum,threenum); 
    int arr [onenum, twonum, threenum];

    return 0;
}

最佳答案

使用这个

int i;
int arr[3];
printf("Enter numbers");
for(i=0;i<3;i++){
    scanf("%d",&arr[i]);
}

这会将用户输入的 3 个数字存储在数组 arr 中。

关于C 程序,用户输入到单个数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39425379/

相关文章:

c - 将变量引用到现有数组

c - 我得到了编译,但我的答案是 0

c - 字符串不允许 float /十进制数

java - 如何使用 bufferedreader 将值分配给直接从输入获取的字符串数组?

java - 为什么需要 ListModel 对象?

android - 如何从属性引用中检索可绘制对象

c 中的 char 数组不适用于 Visual Studio 2015

c++ - 在 Linux 系统调用中的 C 程序中出现错误 ‘\342’ stray ‘\210’ stray ‘\222’

arrays - 不同类型的 RxSwift 变量数组

java - 基本 Java Swing - 在运行时添加带有图标的 JLabels