常量
常量基本特性如下图所示:
常量.png
测试代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HEIGHTBASE 150 // 宏
int main()
{
char name[40];
double weight;
float height;
int letters = 0;
const int WEIGHTBASE = 48;
const double CARDINAL = 0.6;
printf("Hi!你叫什么名字(英文)?\n");
scanf_s("%s", name, sizeof(name));
printf("%s,你有多重(KG)?\n", name);
scanf_s("%lf", &weight);
printf("And, 你有多高(CM)?\n");
scanf_s("%f", &height);
letters = strlen(name);
printf("太棒了!你的名字共计字母%u个!\n", letters);
printf("你的体重为%G,标准体重为%2.2f!\n", weight, (height - HEIGHTBASE)*CARDINAL + WEIGHTBASE);
system("pause");
return 0;
}
输出结果如下所示:
1.png
网友评论