Home > Backend Development > C#.Net Tutorial > How to input ten numbers in C language and output the maximum value

How to input ten numbers in C language and output the maximum value

angryTom
Release: 2020-03-18 15:48:34
Original
43316 people have browsed it

How to input ten numbers in C language and output the maximum value

How to input ten numbers in C language and output the maximum value

The programming method of finding the maximum value among the input 10 numbers in C language is as follows:

1. First, you need to define an integer array space. Because ten numbers need to be entered here, the array space is 10.

int a[10];
Copy after login

2. Then define a maximum value Max. The initial default value is 0. This is used for comparison of subsequent values.

int Max = 0;
Copy after login

3. Then use a for loop to continuously receive input of 10 numbers.

Recommended learning: c language video tutorial

for (int i = 0; i < 10; i++) {
    scanf("%d", &a[i]);
}
Copy after login

4. Use a for loop to loop through the array and find the maximum value Max

for (int i = 0; i < 10; i++) {
  if(a[i] > Max) {
      Max = a[i];
  }
}
Copy after login

5 , after the loop ends, output the final result, which is the maximum value among the 10 numbers we need.

printf("十个数中最大的是:%d", Max);
Copy after login

All the codes are as follows:

#include 

int main() {
    int a[10];
    int Max = 0;
    for (int i = 0; i < 10; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < 10; i++) {
      if(a[i] > Max) {
          Max = a[i];
      }
    }
    printf("十个数中最大的是:%d", Max);
    return 0;
}
Copy after login

PHP Chinese website, a large number of Introduction to Programming Tutorials, welcome to learn!

The above is the detailed content of How to input ten numbers in C language and output the maximum value. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template