数组

 int number[100];   //这个数组可以放100个数
 int x;
 int cnt = 0;
 double sum = 0;
 scanf("%d", &x);
 while ( x != -1 )
 {
     number[cnt] = x;  //对数组中的元素赋值
     sum += x;
     cnt++;
     scanf("%d", &x);
 }
 if ( cnt > 0)
 {
     printf("%f\n", sum/cnt);
     int i;
     for ( i=0; i<cnt; i++ )
    {
         if ( number[i] > sum/cnt)    //使用数组中的元素
        {
             printf("%d\n", number[i]);
        }
    }
 }

定义数组

  • <类型> 变量名称[元素数量];

eg:int grades[100];

double weight[20];

  • 元素数量必须是整数;

  • C99之前:元素数量必须是编译时刻确定的字面量;

  • 一旦创建,不能改变大小;

  • 其中所有的元素都有相同的数据类型;

  • 数组在赋值号左边称为左值,右边称之为右值

  • 数组从0开始数;最大的下标是数组数量-1

  • 出现segmentation faule:可能是数组下标越界

随机推荐

  1. debian(deepin)/ubuntu 安装 mysql5.7

    debian(deepin)/ubuntu 安装mysql5.7 Mysql安装 一.下载安装包 参考博客 https://blog.csdn.net/qq_44231964/article/deta ...

  2. paramiko 文件传输失败 Sftp put 方法 踩坑点

    转载自https://www.cnblogs.com/zhangchen5/p/16064335.html 1. 找不到文件报错 Traceback (most recent call last): ...

  3. mfcc vs fbank

    There is some debate in the community regarding the use of the DCT, instead of directly using the lo ...

  4. Elasticsearch集群部署和运维命令

    Elasticsearch集群部署 下载tar包 在"https://www.elastic.co/cn/downloads/elasticsearch"页面,有 past rel ...

  5. 统计学习导论(ISLR)(三):线性回归(超详细介绍)

    统计学习导论(ISLR) 参考资料: The Elements of Statistical Learning An Introduction to Statistical Learning 统计学习 ...

  6. Color the ball HDU - 1556 _差分

    N名同学拍成一排,编号为1,2,3,4 -- N.现在有一位老师需要检查所有同学的出勤情况,他会进行点名,每次给出两个数a,b,并且保证a小于等于b,这个区间内的所有同学都会被点名一次,老师会进行N次 ...

  7. iOS 扩展与分类的区别

    1.分类 category 分类的作用就是在不修改原有类的基础上,为一个类扩展方法,最主要的是可以给系统类扩展我们自己定义的方法 分类也能使用@property 添加属性 [通过runtime 关联对 ...

  8. ufun对象->NXopen

    Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(SolidVector[i]))); std::vector<Face*& ...

  9. CCPC2021网络赛 1012 Remove

    2021CCPC网络赛 1012 Remove 题意 给定 \(n, m\),然后再给 \(m\) 个素数,问对于所有 \(i \in [1,n]\),将 \(i\) 操作至 \(0\) 的最小操作数 ...

  10. 【相关杂项】stdio.h中的sprintf函数/union的作用

    1.定义int sprintf(char *str, const char *format, ...)         1.paras:*str:目标字符串首指针  *format:要写入目标字符串的 ...