例3.1 有人用温度计测量出用华氏法表示的温度,今要求把它转换为以摄氏法表示的温度。

C程序设计(第四版) 谭浩强 个人设计

例3.1 有人用温度计测量出用华氏法表示的温度,今要求把它转换为以摄氏法表示的温度。

代码块:

#include <stdio.h>
#include <stdlib.h>
void input(double *f);
void transfer(double f);      // Define the transfer function
int main()
{
	double fahrenheit, *p=&fahrenheit;
	input(p);
	transfer(*p);
	system("pause");
	return 0;
}
void input(double *f)
{
	printf("Enter fahrenheit temperature: ");
	scanf("%lf", f);
}
void transfer(double f)
{
	double centigrade;
	centigrade=5*(f-32)/9;
	printf("Centigrade temperature: %lf\n", centigrade);
}

猜你喜欢

转载自blog.csdn.net/navicheung/article/details/98659541