8.8

今天学习了宏的内容
//预处理器在执行宏指令时将程序中出现的“宏”用“字符串”代替,这一过程称为宏展开
//例题8.1求圆周长和面积
#include
using namespace std;
#define PI 3.14
int main()
{
float r;
float c, s;
cout << “请输入圆的半径(cm):”;
cin >> r;
c = 2 * PI * r;
s = PI * r * r;
cout << “圆周长为” << c << “厘米” << endl;
cout << “圆面积为” << s << “平方厘米” << endl;
}
//使用宏定义的好处就在于便于代码的维护和理解

//定义带参数的宏,求一个数的平方
#include
using namespace std;
#define square®®*®;
int main()
{
int a = 2, b = 3, c;
c = square(a);
cout << a << “的平方为” << c << endl;
c = square(a + b);
cout << a + b << “的平方为” << c << endl;
}

//利用条件编译,输入一行字母字符,根据需要设定条件编译,使之需要设定条件编译,使之能将字母全改成大写输出,否则小写输出
#include
using namespace std;
#define Mark 1
int main()
{
char c;
do
{
cin.get©;
#ifdef Mark
if ( c >= ‘a’ && c <= ‘z’ )
c = c + 32;
#endif
cout << c;
} while (c!=’\n’);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值