Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Examples - Determining the Largest of Three Numbers

C Language Examples - Determining the Largest of Three Numbers

C Language Examples C Language Examples

We enter three numbers via the screen and find the largest number.

Example

#include

<

stdio.h

int

main

(

)

{

double

n1

,

n2

,

n3

;

printf

(

"

Please enter three numbers, separated by spaces:

"

)

;

scanf

(

"

%lf %lf %lf

"

, &

n1

, &

n2

, &

n3

)

;

if

(

n1

=

n2

&&

n1

=

n3

)

printf

(

"

%.2f is the largest number.

"

,

n1

)

;

if

(

n2

=

n1

&&

n2

=

n3

)

printf

(

"

%.2f is the largest number.

"

,

n2

)

;

if

(

n3

=

n1

&&

n3

=

n2

)

printf

(

"

%.2f is the largest number.

"

,

n3

)

;

return

0

;

}

Running result:



请输入三个数,以空格分隔: 1 2 3

3.00 是最大数。

C Language Examples C Language Examples