问题描述:宏定义转换为头文件
源代码:
源代码:
/长度单位转换-宏定义/
#include<stdio.h>
#define Mile_to_meter 1609 /1英里=1609米/
#define Foot_to_centimeter 30.48 /1英尺=30.48厘米/
#define Inch_to_centimeter 2.54 /1英寸=2.54厘米/
int main(void)
{
float foot,inch,mile;
printf("Input mile,foot and inch:");
scanf("%f%f%f",&mile,&foot,&inch);
printf("%f miles = %f meters\n",mile,mileMile_to_meter);
printf("%f foot = %f centimeter\n",foot,footFoot_to_centimeter);
printf("%f Inch = %f centimeter\n",inch,inch*Inch_to_centimeter);
return 0;
}
宏定义转换为头文件:
length.h
#define Mile_to_meter 1609 /1英里=1609米/
#define Foot_to_centimeter 30.48 /1英尺=30.48厘米/
#define Inch_to_centimeter 2.54 /1英寸=2.54厘米/
main.c
/长度单位转换-宏定义/
#include<stdio.h>
#include"length.h"
int main(void)
{
float foot,inch,mile;
printf("Input mile,foot and inch:");
scanf("%f%f%f",&mile,&foot,&inch);
printf("%f miles = %f meters\n",mile,mileMile_to_meter);
printf("%f foot = %f centimeter\n",foot,footFoot_to_centimeter);
printf("%f Inch = %f centimeter\n",inch,inch*Inch_to_centimeter);
return 0;
}
运行结果:
运行结果程序说明:
include不是真正的C语句,他在编译结束便不存在了,所以他的结尾不用加;
程序参数:
- 输出大小: 149.365234375 KiB
- 编译时间: 0.31s
网友评论