Problems C: Comparative example 4-3 exchanged three real values, and sequentially outputs

1 title

Problems C: Comparative example 4-3 exchanged three real values, and sequentially outputs
the time limit: 1 Sec memory limit: 12 MB
submission: 3062 Resolution: 2232
[Submit] [state] [discussion boards] [proposition al: External Import ]
Title description
keyboard input from a three real numbers, b, c, to exchange by comparing the minimum value is stored in a variable, the maximum value stored in the variable c, the intermediate value stored in the variable b, and the ascending sequentially outputs three numbers a, b, c.

Wrap the end of the output.

Input
Input separated by a space of three real
output
in ascending order of the output of the three real numbers, separated by a space intermediate, minimum front, after a maximum value. Decimal 2 decimal places.

Note wrap at the end.

Sample input
371
Sample Output
1.00 3.00 7.00

2 reference code

#include<stdio.h>
int main(int argc, char const *argv[])
{
	double a[3];
	double temp;
	scanf("%lf%lf%lf",&a[0],&a[1],&a[2]);
	
	for (int i = 1; i <= 2; ++i)
	{
			for (int j = 0; j <=3-i-1; ++j)
				{
					if(a[j]>a[j+1]){
						temp=a[j+1];
						a[j+1]=a[j];
						a[j]=temp;
					}
				}	
	}

	for (int i = 0; i < 3; ++i)
	{
		printf("%.2f%s",a[i]," ");
	}
		printf("\n");
	return 0;
}
Published 321 original articles · won praise 51 · views 40000 +

Guess you like

Origin blog.csdn.net/qq_33375598/article/details/104060076