例2-3 转换数值

华氏温度100度对应的摄氏温度

公式c=5*(f-32)/9

程序

#include<stdio.h>
int main(void)
{
	int celsius,fachr;//定义变量:celsius 摄氏度 ,fahcr 华氏度
	
	fachr=100;//给变量fahr赋值
	
	celsius=5*(fachr-32)/9;//温度计算
	
	printf("fahr=%d,celius=%d\n",fachr,celsius);//调用函数printf()输出结果
	 
	return 0; 
}

结果

fahr=100,celius=37


Process exited after 0.2941 seconds with return value 0
请按任意键继续. . .

分析

使用算术运算符、赋值运算符

posted on 2019-03-11 18:25  凯*凯  阅读(159)  评论(0编辑  收藏  举报

导航