学堂在线笔记.md




2018/1/17









a中低八位全都置1了


[异或](https://baike.baidu.com/item/%E5%BC%82%E6%88%96/10993677?fr=aladdin)
异或:与0异或保持原值,与1异或取反。


算术右移,逻辑右移


###优先级


混合运算是数据类型的转换
将一个非布尔类型的算术值赋给布尔类型时,算术值为0则结果为false,否则结果为true
将一个布尔值赋给非布尔类型时,布尔值为false则结果为0,布尔值为true则结果为1.
c++中才有布尔类型



强制类型转换




第二章

setsprecision设置精度。



#####switch 开关语句

default: n/v 违约;拖欠;缺席;缺陷


#include<iostream>
using namespace std;
int main()
{
    int day;
    cin >> day;
    switch (day)
    {
    case 0:cout << "SUN" << endl; 
    case 1:cout << "MON" << endl;
    case 2:cout << "TUE" << endl; 
    case 3:cout << "WED" << endl; break;//break跳出switch语句。
    case 4:cout << "THUR" << endl; break;
    default:cout << "NONE" << ends; 
    }
    return 0;
}
####while



###do while


翻转输出
#include<iostream>
using namespace std;
int main()
{
    int n, right_digit;
    cout << "Enter a number";
    cin >> n;
    do
    {
        right_digit = n % 10;
        n /= 10;
        cout << right_digit;
    } while (n != 0);
    cout << endl;
    return 0;
}

while和do while的程序对比

do while一定会循环一次,while则不一定
当i小于等于10时左右两边是一样的效果,当大于10时do while会循环一次,左边的则不会;

###for语句

初始语句:循环开始之前是先求解的,而且就求解这一次;一般会定义一个循环控制变量并初始化像下面例子中(int k=1;
表达式1:是一个逻辑表达式,值是bool类型的,当值为真时执行循环体。这个和while的循环条件表达式是一样的
表达式2:是在每次执行完循环体后求解的,一般是循环变量的变化。


###输入一个整数求其所有因子
#include<iostream>
using namespace std;
int main()
{
    int n;
    cout << "Enter a number:";
    cin >> n;
    cout <<"Number"<< n << "factors:";
    for (int k = 1; k < n; k++)
    if (n%k == 0)
        cout << k << " ";
    cout << endl;
    
return 0;
}


###循环的嵌套

2-10 输入一系列整数,统计出正整数个数i和负整数个数j,读入0则结束

//循环的次数为止,选用while
#include <iostream>
using namespace std;
int main() {
    int i = 0, j = 0, n;
    cout << "Enter some integers please (enter 0 to quit):" << endl;
    cin >> n;
    while (n != 0) {
        if (n > 0) i += 1;
        if (n < 0) j += 1;
        cin >> n;
    }
    cout << "Count of positive integers: " << i << endl;
    cout << "Count of negative integers: " << j << endl;
    return 0;
}
//循环和选择嵌套的结构



continue不会结束循环,只是结束当前这一趟循环。

break:1.是用在switch case开关语句中;2.是用在循环中使用break语句使程序的流程直接立刻跳出紧紧包围它的最内层循环。(跳出)

goto:转到程序中你希望的任何一条语句的地方去。


####自定义类型:


##自定义数据类型




####两种类型
auto自动推断类型
decltype:如例子中表示以2作为变量j的初始值,类型与i一致。
delclarationtype的缩写//宣告类型、声明类型




#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    while (1<=n&&n<=100000)
    {
        cout << "Hello World!" << endl;
        n = n - 1;
    }
       
    
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值