自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(48)
  • 收藏
  • 关注

原创 未完成的图

#include <stdio.h>#include <stdlib.h>#include<malloc.h>#define INF 32767#define MAXV 100typedef char InfoType;typedef struct ANode{ int adjvex; struct ANode *nextrac; int weight;}ArcNode;typedef struct Vnode{ In.

2021-11-16 17:38:56 119

原创 对象数组..

#include <iostream>using namespace std;class exam{public: exam() //一定要有空的构造函数,一开始对象数组里没有输入值,要去找无参的构造函数,找不到就报错 { } exam(int n) { m_x=n; } int getx() { return m_x; }private: int m_x;};.

2021-11-04 16:09:12 126

原创 定义一个图书类Book, 用数组记录数据

#include <iostream>using namespace std;class Book{ public: void setbool(string xname ,string xauthor,double xprice)//xname ,xauthor ,xprice 都是形参,用来接收我在main函数里实参的值,来赋给私有的成员变量。 { name=xname; author=xauthor; ...

2021-10-20 20:38:47 698

原创 存折类..

请定义“存折”类,及其相关的客户端代码。请注意编写正确的构造函数。存折类的基本情况如下:Type name:AccountTypeDomain: Id,name,balance;Operations: Deposit, 存钱操作; Withdraw,取钱操作; getBalance,获取余额操作; WriteAccount,打印帐户信息;Input:13001 peter 01200 //存的钱500 //取的钱Output:13001 peter 700输入130...

2021-10-18 21:39:37 491

原创 构造函数和析构函数

C++使用成员函数给数据成员赋初值既不方便也容易忘记,甚至可能出错,C++提供了一个更好的方法,利用构造函数来完成对象的初始化 构造函数是一种特殊的成员函数,它主要用于为对象分配空间,进行初始化注意:1.构造函数的名字必须与类名相同 2.他可以有任意类型的参数,但不能具有返回值类型 3.他不需要用户调用,而是在建立对象时自动执行的#include <iostream>#include<cma...

2021-10-17 20:15:31 104

原创 门牌号(取多位数各个位数)

#include <iostream>using namespace std;int main(){ int res=0; for(int i=1;i<=2020;i++) { int tmp=i; while(tmp) { res+=(tmp%10==2);//遍历四遍,第一次遍历四位数时,找到最后一位的2的个数,第二次遍历3位数,找到最后一位2的个数 tmp/=10;.

2021-10-14 17:59:56 225

原创 sort()

是一种类似快速排序的方法,时间复杂度为n*log2(n)在C++中使用sort()函数需要使用#include<algorithm>头文件模板:sort(begin,end,cmp) begin为指向待sort()的数组的第一个元素的指针,end为指向待sort()的数组的最后一个元素的下一个位置的指针,cmp参数是排序准则(默认为从小到大排序),从大到小排序可以将cmp参数写为greater<int>()大佬关于sort函数的讲解:C++ sort()排...

2021-10-13 15:37:43 40

原创 静态本地变量

static一般的本地变量,在走出函数后,这个变量的作用就消失了,这一轮所产生的值也消失了但静态本地变量,当函数离开的时候,会继续存在并保持其值静态本地变量的初始化只会在第一次进入这个函数时做,以后进入函数时会保持上一次离开时的值...

2021-10-07 16:07:20 105

原创 给结构体起别名

将这个结构体命名为Date

2021-10-07 15:50:28 1026

原创 结构类型.

一。结构成员出现在.的左边的一定是结构变量,结构变量才是实体.叫取成员,取的是结构体里的成员

2021-10-07 15:30:14 35

原创 结构体。。。

#include <stdio.h>#include <stdlib.h>struct date//结构体 声明了一个struct date { int month; int day; int year; };int main(){ struct date today;// 定义了一个变量叫做struct date today,变量名字叫做today,类型是struct date today.month=07;.

2021-10-06 16:53:23 51

原创 枚举....

2021-10-06 16:40:54 36

原创 字符串函数

1.size_t strlen(const char*s),返回s的字符串长度(不包括结尾的0)#include <stdio.h>#include <stdlib.h>#include<string.h>int mylen(const char* s){ int cnt=0; int idx=0;//数组下标 while(s[idx]!='\0')//遍历数组,去找下标为\0的单元 { idx++;

2021-10-06 16:21:44 80

原创 字符串...

以0(整数0)结尾的一串字符0或‘\0’是一样的,但是和‘0’不同0标志字符串的结束,但他不是字符串的一部分计算字符串长度的时候不包含这个0字符串以数组的形式存在,以数组或指针的形式访问更多的使用指针的形式string.h里有很多处理字符串的函数字符串是数组指针型是常量,利用数组可以去修改...

2021-10-05 22:08:05 43

原创 指针的运算

#include <stdio.h>#include <stdlib.h>int main(){ char ac[]={0,1,2,3,4,5,6,7,8,9}; char *p=ac;//定义一个指针P指向ac的第一个单元 printf("p=%p\n",p);//输出p的地址 printf("p+1=%p\n",p+1); int ai[]={0,1,2,3,4,5,6,7,8,9}; int *q=ai; .

2021-10-05 15:24:24 38

原创 利用指针来交换两个数的值

#include <stdio.h>#include <stdlib.h>void swap(int *pa,int *pb);int main(){ int a=5; int b=6; swap(&a,&b); printf("a=%d,b=%d",a,b); return 0;}void swap(int *pa,int *pb){ int t=*pa; *pa=*pb; *pb=t;.

2021-10-05 12:29:51 974

原创 指针...

一.指针就是一种变量类型,就像int只能存整形数据,double只能存浮点型数据,指针只能存地址数据二。当我们定义一个函数的变量类型为指针时,那在调用时,给指针类型传的数据的类型,必须是地址类型&a,这样就实现了,在函数f()内部访问函数外的内容,利用指针去找到了f()函数外的内容的地址,从而找到这个数据,让他进入函数来进行操作。注意,访问的是外面那个变量的地址,而不是具体的值,也就意味着,通过变量地址来找,若不用指针,得到的仅仅是那个变量的值,我们f()函数,在调用时,希望的是不仅仅局限于这一

2021-10-05 12:29:19 52

原创 push—back函数

push_back()函数的用法函数将一个新的元素加到vector的最后面,位置为当前最后一个元素的下一个元素push_back() 在Vector最后添加一个元素(参数为要插入的值)

2021-10-05 11:00:04 1001

原创 利用数组统计数字出现次数

#include <stdio.h>#include <stdlib.h>int main(){ const int number=10;//数组的大小 int x; int count[number];//定义数组 int i; for(i=0;i<number;i++)//初始化数组 { count[i]=0; } scanf("%d",&x); while(x!=-1.

2021-10-04 17:11:13 1691

原创 函数调用.

#include <stdio.h>#include <stdlib.h>void sum(int begin,int end){ int i; int sum=0; for(i=begin;i<=end;i++) { sum+=i; } printf("%d到%d的和是%d\n",begin,end,sum);}int main(){ sum(10,20); sum(20,30);...

2021-10-04 10:37:32 38

原创 条件运算符(好用)

2021-10-04 10:36:51 52

原创 运算符优先级

2021-10-04 10:12:02 46

原创 水仙花数问题

2021-10-04 10:07:00 76

原创 逃逸字符..

2021-10-04 10:06:28 513

原创 猜数字游戏

2021-10-03 12:47:19 243

原创 统计素数求和

#include <stdio.h>#include <stdlib.h>int main(){ int m,n; int cnt=0; int sum=0; int i; scanf("%d %d",&m,&n); if(m==1)//把特殊值1单拿出来 { m=2; } for(i=m;i<=n;i++) { int isPrime=...

2021-10-03 11:54:54 93

原创 九九乘法表

#include <stdio.h>#include <stdlib.h>int main(){ int i,j; int n=9; i=1; while(i<=n) { j=1; while(j<=i) { printf("%d*%d=%d",j,i,i*j); if(i*j<10) { .

2021-10-03 11:04:10 47

原创 求符合给定条件的整数集

#include <stdio.h>#include <stdlib.h>int main(){ int a;//一共三位数,每一位数字的范围都是从a~a+3,所以三重循环,排列组合 scanf("%d",&a); int i,j,k; int cnt=0;//计数,当cnt=6时,就换行,否则就空格 i=a; while(i<=a+3) { j=a; while...

2021-10-01 18:41:46 115

原创 逆序排列数字问题

#include <stdio.h>#include <stdlib.h>int main(){ int x; x=12345; do { int d=x%10; //取余,把5拿了出来 printf("%d ",d); x/=10; //取整,保留前四位 } while (x>0); printf("\n"); return 0;}.

2021-10-01 16:53:18 59

原创 求前n项和

#include <stdio.h>#include <stdlib.h>int main(){ int n; int i; double sum=0.0; scanf("%d",&n); for(i=1;i<=n;i++) { sum+=1.0/i; } printf("f(%d)=%f\n",n,sum); return 0;}#includ...

2021-10-01 16:52:05 228

原创 go to 语句,离开所有循环语句

#include <stdio.h>#include <stdlib.h>int main(){ int x; //int exit=0; int one,two,five;//代表的是相应价值硬币的个数,two*2是指,两角的硬币带来的钱数 scanf("%d",&x); for(one=1;one<x*10;one++) { for(two=1;two<x*10/2;two++) .

2021-10-01 12:13:28 234

原创 凑硬币的问题

#include <stdio.h>#include <stdlib.h>int main(){ int x; int one,two,five;//代表的是相应价值硬币的个数,two*2是指,两角的硬币带来的钱数 scanf("%d",&x); for(one=1;one<x*10;one++) { for(two=1;two<x*10/2;two++) { .

2021-10-01 12:05:46 75

原创 求前五十个素数

#include <stdio.h>#include <stdlib.h>int main(){ int x; int cnt=0; for(x=1;cnt<50;x++)//条件可以不是X { int i; int isPrime=1;//x是素数 for(i=2;i<x;i++) { if(x%i==0) { .

2021-10-01 11:54:20 339

原创 100里的素数,输出出来

#include <stdio.h>#include <stdlib.h>int main(){ int x; for(x=1;x<=100;x++) { int i; int isPrime=1;//x是素数 for(i=2;i<x;i++) { if(x%i==0) { isPrime=0; .

2021-10-01 11:49:24 40

原创 判断一个数是不是素数(for 循环)

#include <stdio.h>#include <stdlib.h>int main(){ int x; scanf("%d",&x); int i; int isPrime=1;//x是素数 for(i=2;i<x;i++) { if(x%i==0) { isPrime=0; break; } } .

2021-10-01 11:43:10 1297

原创 求阶乘,三种方法

#include <stdio.h>#include <stdlib.h>int main() //三种方法实现{ int fact=1; int n; scanf("%d",&n); // for (int i=1;i<=n;i++)//初始条件;循环继续的条件;循环每一轮要做的事情 // { // fact=fact*i; // .

2021-10-01 10:51:59 840

原创 从main函数调用外面的函数

2021-09-27 08:24:34 708

原创 给出三个整数 a, b, c, 如果它们可以构成三角形,返回 true.

bool isValidTriangle(int a, int b, int c) { if(a+b>c&&a+c>b&&b+c>a){ return true; }else{ false; } }

2021-09-16 21:47:28 184

原创 反转一个三位数

int main(int number) { int bai=number/100; cout<<"百分位的值为:"<<bai; int shi=(number/10)%10; cout<<"十分位的值为:"<<shi; int ge=number%100%10; cout<<"个位的值为:"<<.

2021-09-16 15:38:43 91

原创 函数的重载

#include <iostream>//函数重载,同名的函数,不同的参数类型,根据赋值的值的类型去走不同的函数using namespace std;int square(int i){ return i*i;}long square(long l){ return l*l;}double square(double d){ return d*d;}int main(){ int i=12; long l=1234; .

2021-09-15 15:12:31 30

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除