提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
一、题目
二、代码
代码如下(示例):
#include<iostream>
#include<cmath>
using namespace std;
int main(void)
{
float a,x,y,m;
cin>>a;
y=a/2.0;
do
{
x=0.5*(y+a/y);
m=y;
y=x;
}while(fabs(x-m)>1e-6);
cout<<"a的平方根为:"<<x<<endl;
return 0;
}
#include<iostream>
using namespace std;
double sqrt(double x,double y,double z,double w)
{
double r;
r=(x+y+z+w)/4;
return r;
}
int main()
{
double a,b,c,d,e;
cout<<"请输入四个实数"<<endl;
cin>>a>>b>>c>>d;
e=sqrt(a,b,c,d);
cout<<"这四个数的平均值为:"<<e<<endl;
return 0;
}
代码如下(示例):
#include<iostream> using namespace std; int jishu(int x) { int a=0,p; p=x%2; if(p!=0) a=a+1; return a; } int oushu(int y) { int b=0,q; q=y%2; if(q==0) b=b+1; return b; } int main() { int x,i=0,k=0,a=0,b=0; cin>>x; while(x!=0) { a=jishu(x); if (a==1) i=i+1; b=oushu(x); if(b==1) k=k+1; cin>>x; } cout<<"该序列中奇数个数为:"<<i<<endl; cout<<"该序列中偶数个数为:"<<k<<endl; return 0; } #include<iostream> #include<cmath> using namespace std; double jl(double x1,double y1,double x2,double y2) { double d; d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); cout<<d; return d; } int main() { double x1,x2,y1,y2,r,d,l,s,pi; cin>>x1>>x2>>y1>>y2; r=jl(x1,y1,x2,y2); d=2*r; pi=2*asin(1); l=pi*d; s=pi*r*r; cout<<"该圆半径为:"<<r<<"直径为:"<<d<<"周长为:"<<l<<"面积为:"<<s<<endl; return 0; }