随笔分类 -  C++

摘要:#include <iostream> using namespace std; //函数定义 //语法 //返回值类型 函数名 (参数列表) //{ //函数语句 //return表达式 //} int add(int num1, int num2) { int sum = num1 + num2 阅读全文
posted @ 2021-09-04 13:30 梦之心 阅读(38) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //二维数组案例-考试成绩统计 //1.创建二维数组 int scores[3][3] = { {100,100,100}, {90,50,100}, {60,70,80} }; string 阅读全文
posted @ 2021-09-04 13:21 梦之心 阅读(153) 评论(0) 推荐(0)
摘要:#include <iostream> #include<string> using namespace std; int main() { //二维数组名称用法 int arr[2][3] = { {1,2,3,}, {4,5,6} }; cout << "二维数组占用内存空间为:" << siz 阅读全文
posted @ 2021-09-04 13:20 梦之心 阅读(121) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //二维数组定义 /* 1.数据类型 数组名[行数][列数]; 2.数据类型 数组名[行数][列数]={{数据1,数据2},{数据2=3,数据4}}; 3.数据类型 数组名[行数][列数]={ 阅读全文
posted @ 2021-09-04 13:17 梦之心 阅读(208) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { int arr[] = { 4,2,8,0,5,7,1,3,9 ,15,17,14 }; cout << "排序前" << endl; for (size_t i = 0; i < (size 阅读全文
posted @ 2021-09-04 11:28 梦之心 阅读(77) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //实现数组元素逆置 //1.创建数组 int arr[] = { 1,2,3,4,5,6 }; cout << "逆置前数组" << endl; for (size_t i = 0; i < 阅读全文
posted @ 2021-09-04 11:23 梦之心 阅读(298) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //创建5只小猪体重 int arr[] = { 300,350,200,400,250,100,50 }; int max = 0;//设置一个最大值 //从数组中找到最大的 for (si 阅读全文
posted @ 2021-09-04 10:52 梦之心 阅读(104) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //数组名用途 //1.可以通过数组名统计整个数组占用的内存大小 int arr[] = { 1,2,3,4,5,6,7,8,9,10 }; cout << "整个数组占用的内存空间为;" < 阅读全文
posted @ 2021-09-04 10:40 梦之心 阅读(57) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //数组 //1.数据类型 数组名[数组长度]; //2.数据类型 数组名[数组长度]={值1.值2...}; //3.数据类型 数组名[]= {值1.值2...}; //1.数据类型 数组名 阅读全文
posted @ 2021-09-04 09:52 梦之心 阅读(185) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //goto语句 cout << "1.xxxxxxxxxx" << endl; cout << "2.xxxxxxxxxx" << endl; goto AA;//跳转到标记 cout << 阅读全文
posted @ 2021-09-04 09:44 梦之心 阅读(47) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { for (size_t i = 0; i < 100; i++) { //如果是奇数输出,偶数不输出 if (i % 2 == 0) { continue;//到此为止不在执行,执行下次循环 阅读全文
posted @ 2021-09-04 09:34 梦之心 阅读(51) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //break使用 //1.switch语句中; cout << "选择副本难度" << endl; cout << "1.普通" << endl; cout << "2.中等" << end 阅读全文
posted @ 2021-09-04 09:32 梦之心 阅读(50) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //乘法口诀表 //1×1 = 1 //1×2 = 2 2×2 = 4 //1×3 = 3 2×3 = 6 3×3 = 9 //1×4 = 4 2×4 = 8 3×4 = 12 4×4 = 1 阅读全文
posted @ 2021-09-04 09:26 梦之心 阅读(100) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //利用嵌套循环打印星图 //外层循环,外执行一次,内执行一轮 for (int i = 0; i < 10; i++) { //内层循环 for (int j = 0; j < 10; j+ 阅读全文
posted @ 2021-09-04 09:12 梦之心 阅读(44) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //敲桌子 //输出1-100; for (int i = 1; i <= 100; i++) { //从100个数字找到特殊数字,打印敲桌子 //如果是7的倍数,个位,十位有7,打印敲桌子 阅读全文
posted @ 2021-09-04 09:10 梦之心 阅读(43) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //for循环 //从数字0打印数字9 for (int i = 0; i < 10; i++) { cout << i << endl; } system("pause"); return 阅读全文
posted @ 2021-09-04 09:04 梦之心 阅读(44) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //1.打印所有的三位数字 int num = 100; do {//2.从所有三位数字找到水仙花数 int a = 0; int b = 0; int c = 0; int d = 0; a 阅读全文
posted @ 2021-09-04 09:00 梦之心 阅读(150) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //do...while语句 //在屏幕中输出0到9这10个数字 int num = 0; do { cout << num << endl; num++; } while (num < 10 阅读全文
posted @ 2021-09-04 08:46 梦之心 阅读(38) 评论(0) 推荐(0)
摘要:#include <iostream> #include <time.h> using namespace std; int main() { //生成随机数 //添加随机数种子,作用利用当前系统时间生成随机数,防止每次随机数都一样 srand((unsigned int)time(NULL)); 阅读全文
posted @ 2021-09-04 08:32 梦之心 阅读(46) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; int main() { //while语句 //屏幕打印0-9,这10个数字 //避免死循环 int i = 0; while (i<10) { cout << i<< endl; i++; } system("pa 阅读全文
posted @ 2021-09-04 08:20 梦之心 阅读(42) 评论(0) 推荐(0)