Language C maximum array

Title: Number of six inputs, wherein the maximum value taken.

Idea: Suppose a first maximum, take the first comparison with the latter value, if the value behind the big, the latter value will be assumed to be the largest.

Each value until the comparison again, and finally get that is the maximum.

#include<stdio.h>

int main ()

{

float max;

float s=0.0;

float a[6];

int i;

for(i=0;i<6;i++)

scanf("%f",&a[i]);

max = a [0]; // assumed that a [0] is the maximum

for(i=1;i<6;i++)

if (max <a [i] ) / so that each element is compared with max. /

max = a [i]; / * If a [i] is assigned to a large max * /

printf ( "maximum is:% f \ n", max);

/ Outputting value /

}
Input number 6, the maximum number can be derived.

If the minimum number of requirements, if in the "<" to ">" button.

In this program, and if we put for braces {} are omitted go, many places will experience this, to learn to read this program

Published 239 original articles · won praise 3 · Views 3174

Guess you like

Origin blog.csdn.net/it_xiangqiang/article/details/105163865