1. 程式人生 > >用C語言 將三個數從大到小排序

用C語言 將三個數從大到小排序

#include <stdio.h>
int main()
{
	double a = 0.0, b = 0.0, c = 0.0;
	double t = 0.0;
	printf("輸入三個數:");
	scanf("%lf %lf %lf", &a, &b, &c);
	if (a-b <= 1e-7)
	{
		t = a;
		a = b;
		b = t;     /*a是a,b中較大的*/
	}
	if (a-c <= 1e-7)
	{
		t = a;
		a = c;
		c = t;     /*a是a,b,c中較大的*/
	}
	if (b-c <= 1e-7)
	{
		t = b;
		b = c;
		c = t;     /*b是b,c中較大的*/
	}
	printf("從大到小的順序是:%lf  %lf  %lf\n", a, b, c);
	return 0;
}