1 #include <iostream> 2 #include<stdio.h> 3 #include<iomanip> 4 using namespace std; 5 int main() 6 { 7 double m,n,i,t; 8 double s=0,h; 9 cin>>m>>n; 10 t=m; 11 m=m/2; 12 for(i=1;i<n;i++) 13 { 14 if(n==1) 15 { 16 h=t/2; 17 } 18 else if(n>1) 19 { 20 h=m/2; 21 m=h; 22 s=s+4*h; 23 } 24 } 25 s=s+t; 26 cout<<setiosflags(ios::fixed)<<setprecision(2)<<h<<" "<<s<<endl; 27 return 0; 28 }
时间: 2024-10-31 13:30:38