c++Primer4.3节练习

本文包含多个C++编程练习示例,涉及条件判断与循环结构的应用,通过具体代码展示了如何使用逻辑运算符进行条件判断及循环控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

练习4.8

相等性优先级>逻辑与>逻辑或

练习4.9

if(cp && *cp)

如果cp为空指针和cp中的第一个字符不为空则为真。

练习4.10

#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
using namespace::std; 
int main()
{
	int word;
	while (cin >> word && word != 42)
	{
		cout << word << endl;
	}
	system("pause");
	return 0;

}

练习4.11

#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
using namespace::std; 
int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if (a > b && b > c && c > d)
	{
		cout << a << b << c << d;
	}
	else
	{
		cout << "错误" << endl;
	}
	system("pause");
	return 0;

}

练习4.12

i!=j<k     //因为小于号的优先级大于不等于号所以右边返回一个bool类型0或1 则判断i与1或0的关系

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值