數組方法有哪些,數組的簡單使用示例

 2023-12-06 阅读 21 评论 0

摘要:/*==================================================&#
/*============================================================================Name        : TestArray.cAuthor      : lfVersion     :Copyright   : Your copyright noticeDescription : 數組的簡單使用示例============================================================================*/#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
#define NUM 5
void getAverage();
void searchMax();int main(void) {getAverage();//searchMax();return EXIT_SUCCESS;
}/*** 獲取幾個數的平均值*/
void getAverage(){int total=0;int intArray[SIZE];int i;for(i=0;i<SIZE;i++){scanf("%d",&intArray[i]);total=total+intArray[i];}printf("total=%d\n",total);printf("average=%d",total/SIZE);
}/*** 找出數組中的最大值*/
void searchMax() {int result=0;int array[NUM];int i;for (i = 0; i < NUM; i++) {scanf("%d", &array[i]);}result=array[0];int j;for(j=1;j<NUM;j++){if (array[j]>result) {result=array[j];}}printf("max=%d", result);
}

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/189936.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息