C 语言实例
以下实例演示了交换两个浮点数的值。
实例
#include <stdio.h>
int main()
{
double firstNumber, secondNumber, temporaryVariable;
printf("输入第一个数字: ");
scanf("%lf", &firstNumber);
printf("输入第二个数字: ");
scanf("%lf",&secondNumber);
temporaryVariable = firstNumber;
firstNumber = secondNumber;
secondNumber = temporaryVariable;
printf("\n交换后, firstNumber = %.2lf\n", firstNumber);
printf("交换后, secondNumber = %.2lf", secondNumber);
return 0;
}
运行结果:
输入第一个数字: 1
输入第二个数字: 2
交换后, firstNumber = 2.00
交换后, secondNumber = 1.00
C 语言实例