Simple array use example, simple array use example

Source: Internet
Author: User

Simple array use example, simple array use example

/* ===================================================== ============================================================ Name: testArray. c Author: lf Version: Copyright: Your copyright notice Description: simple array use example ====================================================== ========================================================== = */# include <stdio. h> # include <stdlib. h ># define SIZE 5 # define NUM 5 void getAverage (); void searchMax (); int main (void) {getAverage (); // searchMax (); return EXIT_SUCCESS ;} /*** get the average of several numbers */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);}/*** find the maximum value in the array */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 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.