Calculate the maximum value of 10 integers in C Language

Source: Internet
Author: User

Calculate the maximum value of 10 integers in C Language
We know that to calculate the maximum value of three integers, we can define three variables to store these three values, but if there are ten, one hundred, one thousand, it makes no sense to define so many variables. How can this problem be solved? At this time, we can use an array to store the values we need to compare. For example, we can use a [10] for ten values. Beautiful, concise, and efficient! The data storage solution is comparison. First define a variable, such as MAX, to store one of the ten values and then compare them one by one. But for convenience, we usually select the first value of the array, that is, a [0], to assign a value to the variable, and then compare it with a [1], a [2], and order in sequence. If MAX is less than a [1], the value of a [1] is assigned to MAX and then compares with a [2. The C language code is as follows:

# Include <stdio. h> int main () {int I, MAX, a [10]; printf ("Enter the ten numbers to be compared:"); for (I = 0; I <10; I ++) scanf ("% d", & a [I]); MAX = a [0]; for (I = 0; I <10; I ++) {if (a [I]> MAX) {MAX = a [I] ;}} printf ("the maximum value of 10 is: % d \ n ", MAX); return 0 ;}

 

TIPS: The return Statement cannot return a "pointer" pointing to the "stack memory" because the function body is automatically destroyed when it ends.

Related Article

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.