C++实战代码4

代码1集合

#include
using namespace std;
//const double pi=22.0/7;
//double area(double ra);
//double cir(double ra);
//int main()
//{
//	jump:
//	cout<<"enter your circle's r"<
//	double r;
//	cin>>r;
//	cout<<" area:"<
//	cout<<"cir"<
//	goto jump;
//	return 0;
//}
//double area(double ra)
//{
//	return pi*ra*ra;
//}
//double cir(double ra)
//{
//	return pi*2*ra;
//}



//double surfacearea(double r,double h);
//double tiji(double r,double h);
//int main()
//{
//	cout<<"输入圆柱的半径和高"<
//	double h,r;
//	cin>>r;cin>>h;
//	cout<<"圆柱的表面积="<
//	cout<<"圆柱的体积="<
//	return 0;
//}
//double surfacearea(double r,double h)
//{
//	return 2*pi*r*r+2*pi*r*h;
//}
//double tiji(double r,double h)
//{
//	return pi*r*r*h;
//}

//裴诺伊数列(输入一个数字,得出这个位置的值)
int x(int y)
{
	if(y<2)
		return y;
	if(y>=2)
		return x(y-1)+x(y-2);
}
int main()
{
	jump:
	cout<<"input a number y="<<endl;
	int y=0;
	cin>>y;
	cout<<"x(y)=="<<x(y)<<endl;
	goto jump;
	return 0;
}循环输出
# 代码2:实现输入任意个数数字并实现复制输出
#include
using namespace std;
int main()
{
	cout<<"how many number do you want to enter?"<<endl;
	int input=0;
	cin>>input;
	int* padr=new int[input];
	int* pcopy=padr;
	cout<<"successful memory "<<input<<endl;
	for(int x=0;x<input;++x)
	{
		cout<<"enter number is "<<x<<":";
		cin>>*(padr+x);//实现输入数字地址随着X游标数值增加而增加。
		cout<<padr+x<<endl;
		cout<<pcopy+x<<endl;
	}
	cout<<"display all numbers are:"<<endl;
	int y=0;//这里我是把定义y的类型并对其赋值放在下一个for循环前面,不然放进去,程序无法运行会报错。
	for(int* pcopy=padr;y<input;++y)
		cout<<*(pcopy++)<<" ";//输出值
		cout<<pcopy+y<<endl;
	cout<<endl;
	delete[] padr;
	return 0;
}//实现输入任意个数数字并实现复制的功能

你可能感兴趣的:(C++实战代码4)