1、将华氏温度转换为摄氏温度和绝对温度的公式分别为:
c=5/9(f-32) (摄氏温度)
k=273.16+c (绝对温度)
请编程序:当给出 f 时,求其相应摄氏温度和绝对温度
测试数据:
-
f=34
#include<stdio.h>
main()
{
float c,f,k;
printf("f=");
scanf("%f",&f);
c=5.0/9*(f-32);
k=273.16+c;
printf("c=%.lf,k=%.lf\n",c,k);
}
-
f=100
2、写一个程序把极坐标(r,θ)(θ之单位为度)转换为直角坐标(x,y)。转换公式是:
x=r.cosθ
y=r.sinθ
测试数据:
1.r=10 θ=45°
#include<stdio.h>
#include<math.h>
#define PI 3.1415926
main()
{
double x,y,r,tht;
printf("input:\n");
scanf("%lf%lf",&r,&tht);
x=r*cos(tht*PI/180);
y=r*sin(tht*PI/180);
printf("x=%f,y=%f\n",x,y);
}
2.r=20 θ=90°