Compare commits

..

No commits in common. "4adc5f40578f81911941bc0f9439579ec1f65c55" and "12e18ec4154db36c350a12836e3db198a37db584" have entirely different histories.

10 changed files with 1 additions and 159 deletions

3
.gitignore vendored
View File

@ -92,5 +92,4 @@ dkms.conf
*.s *.s
*.o *.o
*.swp *.swp
.vscode .vscode
*/test

View File

@ -1,19 +0,0 @@
// 打印九九乘法表
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < 10; j++)
{
if (j <= i)
cout << i << "*" << j << "=" << i * j << "\t";
}
cout << endl;
}
return 0;
}

View File

@ -1,23 +0,0 @@
// 源码反码补码
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
int z = -9;
cout << bitset<8>(z) << endl;
cout << bitset<8>(z >> 1) << endl; // 右移一位符号位不变左边补1
cout << bitset<8>(z << 1) << endl; // 左移一位符号位不变右边补0
cout << dec << z << endl; // 十进制
cout << oct << z << endl; // 八进制
cout << hex << z << endl; // 十六进制
signed int x = 20;
cout << bitset<8>(x) << endl;
cout << bitset<8>(x >> 1) << endl; // 右移一位符号位不变左边补0
cout << bitset<8>(x << 1) << endl; // 左移一位符号位不变右边补0
return 0;
}

View File

@ -1,14 +0,0 @@
// 无符号数
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
unsigned char a = 255, b = 0, c = 0x30;
cout << bitset<8>(a) << "," << dec << (int)a << endl;
cout << bitset<8>(b) << "," << dec << (int)b << endl;
cout << bitset<8>(c) << "," << dec << (int)c << endl;
return 0;
}

View File

@ -1,12 +0,0 @@
// 进制转换
#include <iostream>
using namespace std;
int main()
{
int n1 = 037, n2 = 0x3a;
cout << "037 = " << n1 << endl; // 以10进制输出八进制数
cout << "0x3a = " << n2 << endl; // 以10进制输出十六进制数
return 0;
}

View File

@ -1,12 +0,0 @@
// 测试负数的二进制表示:补码方式存储
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
int x = -123;
cout << bitset<8>(x) << endl;
return 0;
}

View File

@ -1,25 +0,0 @@
// sizeof测试
#include <iostream>
using namespace std;
int main()
{
char c = 'a';
cout << c << endl;
cout << sizeof(c) << endl;
short x = '1';
cout << x << endl;
cout << sizeof(x) << endl;
int z = 1;
cout << z << endl;
cout << sizeof(z) << endl;
bool y = true;
cout << y << endl;
cout << sizeof(y) << endl;
return 0;
}

View File

@ -1,16 +0,0 @@
// 测试一个整数能否被3整除
#include <iostream>
using namespace std;
int main()
{
unsigned int n;
cout << "请输入一个整数:";
cin >> n;
if (n % 3 == 0)
cout << "能被3整除" << endl;
else
cout << "不能被3整除" << endl;
return 0;
}

View File

@ -1,20 +0,0 @@
// 测试随机数
#include <iostream>
#include <cstdlib> // C++兼容C语言的标准库
#include <ctime> // C++兼容C语言的时间库
using namespace std;
// stand(数值) 设置随机数种子, 一般使用 time(NULL) 获取当前时间 (相对于1970年1月1日的秒数) 作为随机数种子
// rand() 生成 0 ~ RAND_MAX 之间的随机数
// 如果随机产生 (min, max) 区间的随机数, 可以使用 rand() % (max - min + 1) + min
int main()
{
// 将当前时间作为随机数种子 (作用: 不同时间产生的随机数不同)
srand(time(NULL)); // 设置随机数种子
// 生成 60~100 之间的随机数
int num = rand() % 41 + 60;
cout << num << endl;
return 0;
}

View File

@ -1,16 +0,0 @@
// 测试goto语句
#include <iostream>
using namespace std;
int main()
{
cout << "1" <<endl;
cout << "2" <<endl;
goto FLAG;
cout << "3" <<endl;
cout << "4" <<endl;
FLAG:
cout << "5" <<endl;
return 0;
}