![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
wsc_168
这个作者很懒,什么都没留下…
展开
-
二维数组的初始化及访问方式
二维数组的初始化及访问C++可以模拟多维数组,但存储数组的内存是一维的。编译器将多维数组映射到内存,而内存只沿一个方向延伸。在C++定义二维数组并使用函数初始化#include <iostream>using namespace std;const int ARRAY_LENGTH = 5;void init_array(int (*p)[ARRAY_LENGTH],...原创 2020-04-25 18:35:53 · 321 阅读 · 0 评论 -
查找1到100之间的素数
查找1到100之间的素数一个正整数,如果只有1和它本身两个因数,则叫做素数,也叫做质数。代码实现如下:#include <iostream>#include <vector>using namespace std;bool isPrime(int data) { for (int i = 2; i < data - 1; i++) { if...原创 2020-04-18 23:13:17 · 1278 阅读 · 0 评论 -
使用模板函数判断一个数组是否有序
判断一个数组是否有序编写一个模板函数 is_sorted,当且仅当a[0:n-1]有序时, 返回值是true。#include <iostream>using namespace std;template <class T>bool is_sorted(T* a, int n) { int toLow = 0; int toHigh = 0; in...原创 2020-04-14 23:00:43 · 618 阅读 · 0 评论