自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

小白的成长

准备复试,自学C++中,会把自己的作业都上传上来做个备份。

  • 博客(22)
  • 收藏
  • 关注

原创 函数指针,求两个数最大值,求和

#include <iostream>using namespace std;int compute(int a,int b,int(*func)(int,int))//定义函数指针,该指针指向函数的首地址{return func(a,b);}int max(int a,int b){return a>b?a:b;}int sum(int a ,int b){...

2020-02-12 11:42:09 1111

原创 输入一个二维矩阵,转置并输出

输入9个数字,构成3×3二维矩阵,输出矩阵,然后转置再输出#include <iostream>using namespace std;void swap(int &a,int &b)//转置函数,必须用引用{ int temp=a; a=b; b=temp;}int main() { int a[3][3]; int i,j; cout&lt...

2020-02-08 11:57:07 3469

原创 初始化一個二位數組,求出每一行的和

初始化一個二位數組,求出每一行的和#include <iostream>using namespace std;void rownum(int A[][4],int nrow)//計算二維數組A每一行的和,nrow是行數,數組的列數是4 { for(int i=0;i<nrow;i++) { for(int j=1;j<4;j++) A[i][0]+...

2020-02-04 11:42:43 152

原创 數組:輸出斐波那契数列前20個數

#include <iostream>using namespace std;int main() { int i; int ay[20]; // ay[0]=ay[1]=1;//這兩行也可以換成 int ay[20]={1,1}; for(i=2;i<20;i++) ay[i]=ay[i-1]+ay[i-2]; for(i=0;i<20;i++) ...

2020-02-04 10:57:25 706

原创 作用域与可见性实例

#include <iostream>using namespace std;int i; //全局变量,文件作用域 int main() { i=5; //文件作用域的i赋初值 { //子块 int i; //局部变量,块作用域 i=7; cout<<i<<endl; //输出7 } ...

2020-01-29 12:48:45 128

原创 声明一个矩形类

class Rectangle{ public: Rectangle(int left,int down,int right,int up) ~Rectangle(){} int Getleft{return itsleft;} int Getdown{return itsdown;} int Getright{return itsright;} int Getup{return ...

2020-01-22 13:33:36 402

原创 声明一个Dog类

包含年龄、身高等属性,能够输入输出这些属性#include <iostream>using namespace std;class Dog{ public: Dog(int initialAge=0,int initialWeight=5); ~Dog(); int GetAge(){return itsAge;} void SetAge(int age){...

2020-01-22 10:45:16 1450

原创 时钟类的完整程序

#include <iostream>using namespace std;class clock{public: void settime(int newh = 0, int newm = 0, int news = 0); void showtime();private: int hour, minute, second;};void clo...

2020-01-19 12:46:57 1874

原创 求最大公约数

#include<iostream>using namespace std;int main(){ int f(int n1,int n2); int n1, n2; cout << "输入两个数: "; cin >> n1 >> n2; cout<<f(n1,n2);}int f(int n1,int n2){...

2020-01-18 13:35:25 112

原创 求最小公倍数

#include<iostream>using namespace std;int main(){ int LCM(int n1,int n2); int n1, n2; cout << "输入两个数: "; cin >> n1 >> n2; cout<<LCM(n1,n2);} int LCM(int n1,int...

2020-01-18 13:31:10 163

原创 编写函数把华氏温度转换为摄氏温度

#include <iostream>using namespace std;double trans(double f){ double c; c=(f-32)*5/9; } int main() { double f; cin>>f;//输入华氏温度 cout<<endl<<trans(f);//输出摄氏温度 }...

2020-01-18 12:48:08 9509

原创 递归:求x的y次幂

#include <iostream>using namespace std;double dg(int x,int y){ if(y==0) return 1; else return x*dg(x,y-1); } int main(){ int x; int y; cout<<"请输入x和y"<<endl; cin>>x...

2020-01-18 11:52:39 3171 1

原创 递归:求n阶勒让德多项式的值

#include <iostream>using namespace std;double dg(int n,double x){ if(n==0) return 1; else if(n==1) return x; else return ((2*n-1)*x*dg(n-1,x)-(n-1)*dg(n-2,x)); } int main(){ cout<&...

2020-01-18 11:41:58 603

原创 递归:求正整数的前n项和

#include <iostream>using namespace std;int dg(int n){ if(n==1) return 1; else return n+dg(n-1); } int main(){ int f; cout<<"请输入一个正整数"<<endl; cin>>f; cout<<e...

2020-01-18 11:13:41 898

原创 递归:n个人里面选出k个

#include <iostream>using namespace std;int comm(int n,int k){ if(k>n) return 0; else if(n==k||k==0) return 1; else return comm(n-1,k)+comm(n-1,k-1);}/* run this program using the cons...

2020-01-18 10:05:19 419

原创 递归:求整数的阶乘

#include <iostream>using namespace std;double fac(int n)//用double型可以计算大数据的阶乘,比如99!{ double f; if(n==0) f=1; else f=fac(n-1)*n; return(f);} int main() { double fac(int n); int n; do...

2020-01-18 09:39:14 546

原创 输出100以内的质数

自己瞎写的竟然运行成功了,感觉代码还是有点问题,再研究研究。#include<iostream>using namespace std;int main(){ int i; int j; for(i=2;i<=100;i++){ for(j=2;j<=i;j++){ if(i!=j&&i%j==0) break; ...

2020-01-17 15:08:32 136

原创 输出ASCII码为32~127的字符

#include<iostream>using namespace std;int main(){ char a; //必须用char类型定义变量a for(a=32;a<=127;a++) //从ASCII为32开始到127,依次输出该字符 cout<<a<<" "; //两字符中间用空格分开 retur...

2020-01-17 14:49:01 6408 2

原创 设定一个数字,让用户去猜

用 while 实现:#include <iostream>using namespace std;int main() { int n,i; n=39;//这个需要猜数字预先设定好 cin>>i; while(i!=n){ if(i<n) cout<<"too small"<<endl; else cout<&lt...

2020-01-17 14:41:18 368

原创 声明一个表示时间的结构体

#include <iostream>#include <iomanip>using namespace std;struct time{ int year; int month; int day; int hour; int minute; int second;}; //声明一个time结构体int main() { time now;//定...

2020-01-17 14:25:09 3143 1

原创 输入考试分数,判断等级

#include <iostream>using namespace std;int main() { int n; cout<<"你考了多少分?"; cin>>n; cout<<"你的等级是:"; if(n>=90&&n<=100) cout<<"优"; else if(n>=8...

2020-01-16 17:04:23 1044

原创 输出九九乘法表

输出九九乘法表#include<iostream>using namespace std;int main(){ int i,j=0; for(i=1;i<=9;i++) { for(j=i;j<=9;j++) cout << i << '*' << j << '=' << i*j<&...

2020-01-16 15:55:02 290 2

空空如也

空空如也

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

TA关注的人

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