
c++
Gardenia Minwentel
这个作者很懒,什么都没留下…
展开
-
C++中的double类型——关于保留小数位数的探讨
C++中的double类型是表示双精度浮点型那单纯的使用double类型是保留到小数后的第几位呢?准确来说,double不是确切地保留到小数后第几位,而是保留多少位有效数字。 C++中的double类型是保留6位有效数字。这个还得从计算机的内部数值存储说起:对于小数,计算机术语为 浮点数。所谓浮点,顾名思义就是小数点可以浮动,可以移动。可以参见唐朔飞编写的《计算机组成原理》小数在计算...原创 2020-02-25 09:45:40 · 27500 阅读 · 4 评论 -
c++实现输出一个0和1分别分布在主对角线两侧的矩阵
#include "stdafx.h"#include <iostream>using namespace std;//输出一个0和1分别分布在主对角线两侧的矩阵//4*4的矩阵#define N 4int _tmain(int argc, _TCHAR* argv[]){ int a[N][N]; int i,j; for(i=0;i<N;i++) fo...原创 2019-01-10 08:26:52 · 918 阅读 · 0 评论 -
c++实现输出杨辉三角
#include "stdafx.h"#include<iostream>using namespace std;#include <iomanip>//写一个函数,通过调用函数,实现打印输出杨辉三角的前10行int _tmain(int argc, _TCHAR* argv[]){ int yanghui[10][10],i,j; void yanghu...原创 2019-01-10 08:28:52 · 6572 阅读 · 1 评论 -
c++写一个函数,实现输入一个字符串,将其中的字符按逆序输出
#include "stdafx.h"#include <iostream>#include <string.h>using namespace std;#define N 20int _tmain(int argc, _TCHAR* argv[]){ char str[N]; void string_reverse(char s[],int n); c...原创 2019-01-10 08:32:10 · 6310 阅读 · 1 评论 -
c++利用指针写一个strcmp函数
#include "stdafx.h"#include <iostream>using namespace std;#include <string.h>//利用指针写一个strcmp函数int _tmain(int argc, _TCHAR* argv[]){ char str1[10]="abcde",str2[10]="abcfgh",*p1,*p2...原创 2019-01-10 08:41:22 · 710 阅读 · 0 评论 -
c++二分查找
#include "stdafx.h"#include<iostream>using namespace std;#define N 15//折半查找:适用于事先排好序的数组int _tmain(int argc, _TCHAR* argv[]){ int a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; int i; cout...原创 2019-01-10 08:45:35 · 897 阅读 · 0 评论 -
c++通过运算符重载实现两个矩阵相加
#include "stdafx.h"#include <iostream>#include <iomanip>using namespace std;//矩阵运算的类class Matrix{private: int row;//行 int col;//列 int **mat;//指向一级指针变量的二级指针,二级指针变量名可以看做二维数组的数组名p...原创 2019-01-10 08:49:29 · 10206 阅读 · 2 评论 -
c++写一个函数验证哥德巴赫猜想
//写一个函数验证哥德巴赫猜想int _tmain(int argc, _TCHAR* argv[]){ void godbaha(int n); int x; bool prime(int m); cout&lt;&lt;"Please input a number:"&lt;&lt;endl; cin&gt;&gt;x; godbaha(x)原创 2019-01-21 10:41:35 · 10495 阅读 · 2 评论 -
c++实现插入排序
#include &quot;stdafx.h&quot;#include&amp;lt;iostream&amp;gt;using namespace std;#define N 10//插入排序int _tmain(int argc, _TCHAR* argv[]){ int x,i,j; int a[N+1]={1,2,3,6,7,8,9,11,16,26}; cout&amp;lt;&原创 2019-01-21 10:34:19 · 136 阅读 · 0 评论 -
c++实现将一个十进制数转换成二进制
#include "stdafx.h"#include<iostream>using namespace std;//十进制转二进制int _tmain(int argc, _TCHAR* argv[]){ int x,i=0,j; int a[32]; cout<<"Please input a decimal base:"<<endl; ...原创 2019-01-10 08:25:15 · 15505 阅读 · 0 评论 -
c++实现冒泡排序
#include "stdafx.h"#include<iostream>using namespace std; #define N 10//冒泡排序:两两相邻的数相比,如果不满足排序要求(要求升序或者降序),就进行位置交换//实际每轮是相邻两个数之间比较将最大的数筛选出来了,然后往后面放(大数沉底)int _tmain(int argc, _TCHAR* argv[])...原创 2019-01-10 08:22:50 · 268 阅读 · 0 评论 -
c++中求100以内最大的10个素数
c++中求100以内最大的10个素数,并将这10个最大的素数按4个一行输出,然后对这10个素数求和思路:判断一个数m是否为素数,需要让2~m-1的所有数来除以m,但是m的因子是成对出现的,所以只需用2~m的平方根来除以m即可,这样可以提高计算速度,优化代码#include &quot;stdafx.h&quot;#include&amp;lt;iostream&amp;gt;#include&amp;原创 2018-09-30 20:20:48 · 5233 阅读 · 0 评论 -
c++中求两个数的最大公约数和最小公倍数(辗转相除法)
辗转相除法原创 2018-10-01 12:20:19 · 16559 阅读 · 6 评论 -
c++中求1!+2!+3!+...+20!(不用递归)
c++中求1!+2!+3!+…+20!(不用递归)#include "stdafx.h"#include<iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int n ; double fac=1,sum=0;//fac用来存放阶乘后的值,sum用于存放累加和 for(n=1;n<...原创 2018-10-01 12:25:46 · 6809 阅读 · 0 评论 -
c++中输出“水仙花数”
输出所有的水仙花数,所谓的“水仙花数”是指一个3位数,其各位数字立方和等于该数本身,例如153是一个水仙花数,因为153=1的立方+5的立方+3的立方#include "stdafx.h"#include<iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ cout<<"水仙花数...原创 2018-10-01 12:35:42 · 6640 阅读 · 0 评论 -
c++实现选择排序
#include "stdafx.h"#include<iostream>using namespace std;#define N 10int _tmain(int argc, _TCHAR* argv[]){//选择法排序,第1轮:先选出最小值和第一个数交换 // 第2轮:在除去第1个数以外的剩下的数当中选出最小的数和第2个数交换... int array...原创 2018-10-01 22:07:05 · 336 阅读 · 0 评论 -
c++中求分数序列2/1,3/2,5/3,8/5,13/8,21/13....前20项的和
求分数序列2/1,3/2,5/3,8/5,13/8,21/13…前20项的和规律:从第二项开始,后一项的分母等于前一项的分子,后一项的分母等于前一项分母与分子之和#include &quot;stdafx.h&quot;#include&amp;lt;iostream&amp;gt;using namespace std;int _tmain(int argc, _TCHAR* argv[]){//求2/1,3/2,原创 2018-10-01 22:18:59 · 15972 阅读 · 4 评论 -
C++中运算符重载实现复数的加减乘除
#include "stdafx.h"#include "Complex.h"#include &lt;iostream&gt;using namespace std;//输入运算符重载istream &amp; operator &gt;&gt;(istream &amp;in,Complex &am原创 2019-01-10 08:16:52 · 5428 阅读 · 0 评论 -
c++中判断三角形
判断三角形(利用分支结构)#include "stdafx.h"#include&lt;iostream&gt;using namespace std;#include&lt;cmath&gt;int _tmain(int argc, _TCHAR* argv[]){ cout&lt;&lt;"请输入三角形的三条边:&quo原创 2018-09-30 20:07:11 · 16510 阅读 · 1 评论