![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
初学C++
JC677
这个作者很懒,什么都没留下…
展开
-
随机数问题
#include #include #include #include using namespace std;int main(){//伪随机数int r;srand(time(0));//以当前时间作为种子,每次循环自动更新//srand(static_cast<int>(time(nullptr)));//若上述语句收到警告,可用此行代替for(int i=0; i<10; i++){ r = rand(); cout << r原创 2021-05-18 21:36:26 · 83 阅读 · 0 评论 -
一直读入直至读入标记值(输入失败)
#include using namespace std;int main(){double salary;int counter = 0;double average;double sum;cout << "Inter salaries, -1 to finish:";while(salary != -1){ cin >> salary; if(salary!=-1) { counter += 1; sum原创 2021-05-13 07:29:35 · 72 阅读 · 0 评论 -
折半查找(C++)
折半查找必须采用顺序存储结构,而且表中元素按关键字有序排列原理与中值比较,不断缩小区间范围代码#include using namespace std;int BinarySearch(int a[], int low, int high, int target){while(low <= high){int mid = low + (high - low); //即(low + high)/2,这样写是防止溢出if(a[mid] > target) //若目标元素小原创 2021-04-18 00:07:38 · 1011 阅读 · 0 评论