1.
C++程序:
#include?<iostream>using?namespace?std;
void?main()?
{
int?i;
double?sum?=?0;
double?height?=?100;
sum?+=?height; //第1次落地,只向下
//第2-9次落地,有下落和反彈
for(i=2;?i<10;?i++)
{
height?/=?2;
sum?+=?height?*?2;
}
height?/=?2;
sum?+=?height; //第10次落地,只向下
cout<<"經過總距離:"<<sum<<endl;
cout<<"第10次反彈高度:"<<height<<endl;
}
運行測試:
2.
C++程序:
#include?<iostream>using?namespace?std;
void?main()?
{
int?ten; //10元幣的數量
int?five; //5元幣的數量
int?one; //1元幣的數量
int?total?=?100;
int?count?=?0;
for(ten=1;?ten<10;?ten++)
{
for(five=1;?five<20;?five++)
{
for(one=1;?one<100;?one++)
{
if(10?*?ten?+?5?*?five?+?one?==?100)
{
cout<<ten<<"?"<<five<<"?"<<one<<endl;
count++;
}
}
}
}
cout<<"***有?"<<count<<"?種兌法"<<endl;
}
運行測試: