c - 为什么我的代码没有给出任何结果

标签 c

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int list[]; /*creating an arry call list*/
int main()
{
    srand(time(NULL));
    void element()/*creating the first element function*/
    {
        int i; 
        for (i=0; i<100; i++){
            list[i] = 100+rand()%900  ;
        }

        for (i=0; i<100; i++){
            printf("%d", list[i]); 
        }
    }
    return 0;
}

我不知道为什么它没有给我任何结果,代码的目的是生成 100 个随机数并将该数字放入数组中。

最佳答案

您需要进行一些更改:

1)除非需要移动它,否则您可以在主函数中执行所有操作。

2)记住您需要设置数组大小(在本例中为 100)。

3)如果使用函数,则需要在主函数之前声明原型(prototype)。

4)您可以使用相同的 for 循环一次来迭代并打印数字。

  #include <stdio.h>
  #include <stdlib.h>
  #include <time.h>

  int main()
 { 
     int list[100]; /*creating an arry call list*/
     srand(time(NULL));

   int i; 
  for (i=0; i<100; i++){
  list[i] = 100+rand()%900  ;
    printf("%d \n", list[i]); 
}

}

关于c - 为什么我的代码没有给出任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44741963/

相关文章:

c - C 中的表达式 "double (f)(double)"可能是什么意思

c++ - 将源代码与 C++ 程序的汇编列表相关联

c - 使用 llvm 提示编译器

c - 从用 C 解析的文件中删除标签

c - 与特定字符串比较后如何过滤缓冲区中的行

c - 为什么 #line 指令没有在 clang 的 false #if 中处理?

c - 在C编程中使用libevent编写非阻塞事件

c - OpenGL - 使用锥形聚光灯创建平面

c - 读取套接字中的缓冲区

c - 查找文本文件中的字符数、单词数和行数