输出华氏-摄氏温度转换表

1、输入两个整数lower和upper,输出一张华氏-摄氏温度转换表,华氏温度的取值范围是[lower,upper],每次增加1华氏度

#include <stdio.h>
int main()
{
    
    
	int fahr,lower,upper;
	double celsius;
	printf("enter lower:");
	scanf("%d",&lower);
	printf("enter upper:");
	scanf("%d",&upper);
	if(lower<=upper)
	{
    
    
		printf("fahr celsius\n");
		for(fahr=lower;fahr<=upper;fahr++)
		{
    
    
			celsius=(5.0/9.0)*(fahr-32);
			printf("%4d%6.1f\n",fahr,celsius);
		}
	}
	else
	{
    
    
		printf("Invalid Value!\n");
	}
	return 0;
}

在这里插入图片描述
2、输入两个整数lower和upper,输出一张华氏-摄氏温度转换表,华氏温度的取值范围是[lower,upper],每次增加2华氏度(C语言程序设计第四版 何钦铭,颜晖 练习2-12)

#include <stdio.h>
int main()
{
    
    
	int fahr,lower,upper;
	double celsius;
	printf("enter lower:");
	scanf("%d",&lower);
	printf("enter upper:");
	scanf("%d",&upper);
	if(lower<=upper)
	{
    
    
		printf("fahr celsius\n");
		for(fahr=lower;fahr<=upper;fahr=fahr+2)
		{
    
    
			celsius=(5.0/9.0)*(fahr-32);
			printf("%4d%6.1f\n",fahr,celsius);
		}
	}
	else
	{
    
    
		printf("Invalid Value!\n");
	}
	return 0;
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_58768870/article/details/127562451