CPP17 计算小球走过的路程和反弹高度
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// 下落的高度和落地的次数
double h;
int n;
cin >> h;
cin >> n;
// write your code here......
double length=h;
h*=0.5;
for(int i=0;i<n-1;i++){
length+=h*2;
h/=2;
}
printf("%.1f %.1f\n", length,h);
return 0;
}
CPP19 获取数组最值
#include <iostream>
using namespace std;
int main() {
int arr[6] = { 0 };
int len = sizeof(arr) / sizeof(int);
for (int i = 0; i < len; i++) {
cin >> arr[i];
}
// write your code here......
int max=arr[0];
int min=arr[0];
for(int i=1;i<len;i++){
if(max<arr[i]){
max=arr[i];
}
if(min>arr[i]){
min=arr[i];
}
}
cout<<min<<" "<<max<<endl;
return 0;
}
|