参考代码1021-1031

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     double c; 
 6     int a,b;
 7     cin>>a>>b;
 8     c=sqrt(a*a+b*b);
 9     printf("%.1lf\n",c);
10     return 0;
11 }

 

1022 两点距离

 1 #include <bits/stdc++.h>           
 2 using namespace std;                
 3 int main()                      
 4 {   
 5     double x1,y1,x2,y2,d;
 6     cin>>x1>>y1>>x2>>y2;//注意输入顺序和输入个数 
 7     d=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
 8     d=sqrt(d);
 9     printf("%.2lf\n",d);
10     return 0;
11   } 

1023 绝对值

 1 #include <bits/stdc++.h>           
 2 using namespace std;                
 3 int main()                      
 4 {   
 5     int a;
 6     double b;
 7     cin>>a>>b;
 8     a=abs(a);
 9     b=fabs(b);
10     cout<<a<<" "<<b<<endl; 
11     return 0;
12   }

 1024 天花板和地板函数

1 #include <bits/stdc++.h>           
2 using namespace std;                
3 int main()                      
4 {   
5     double x;
6     cin>>x;
7     cout<<ceil(x)<<" "<<floor(x)<<endl; 
8     return 0;
9   } 

1025 求平方根

 1 #include <bits/stdc++.h>           
 2 using namespace std;                
 3 int main()                      
 4 {   
 5     double x,y;
 6     cin>>x;
 7     y=sqrt(x);
 8 //    cout<<fixed<<setprecision(3)<<y<<endl;
 9     printf("%.3lf\n",y);
10     return 0;
11   } 

 

1026 n的a次方

 1 #include <bits/stdc++.h>           
 2 using namespace std;                
 3 int main()                      
 4 {   
 5     int n,a;
 6     long long c;
 7     cin>>n>>a;
 8     c=pow(n,a);
 9     cout<<c<<endl;
10     return 0;
11   } 

1027: 与圆相关的计算

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     double r;
 6     double zj,zc,mj;  //分别表示直径,周长,面积 
 7     const double pi=3.14159; 
 8     cin>>r;
 9     zj=2*r;
10     zc=2*pi*r;
11     mj=pi*r*r;
12     printf("%.4lf %.4lf %.4lf\n",zj,zc,mj) ;
13     return 0;
14 } 

1028: 球体体积

 1 #include <bits/stdc++.h>           
 2 using namespace std;                
 3 int main()                      
 4 {   
 5     double r,v;
 6     const double PI=3.1415927;
 7     cin>>r;
 8     v=4.0/3*PI*r*r*r;
 9     printf("%.3lf",v);
10     return 0;
11   } 

1029: 计算曼哈顿距离

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 main()
 4 {
 5     double x1,y1,x2,y2,d;
 6     cin>>x1>>y1>>x2>>y2;
 7     d=fabs(x2-x1)+fabs(y2-y1); 
 8     printf("%.3lf\n",d);
 9     return 0;
10  } 

1030: 特殊输出

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 main()
 4 {
 5     int x,y;
 6     cin>>x>>y;
 7     printf("%*d\n",y,x);
 8     printf("%0*d\n",y,x);
 9     printf("%-*d\n",y,x);
10     return 0;
11  } 

1031: 实数格式化输出

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 main()
 4 {
 5     double x;
 6     int    y;  //表示场宽 
 7     cin>>x>>y;
 8     printf("%*.3lf\n",y,x);
 9     printf("%0*.3lf\n",y,x);
10     printf("%-*.3lf\n",y,x);
11     return 0;
12  } 

 

posted @ 2019-10-16 12:32  MissLin  阅读(199)  评论(0编辑  收藏  举报