當前位置:編程學習大全網 - 網站源碼 - c++編程1.球從100米高度掉落,每次落地反跳原高度的壹半,第10次落地

c++編程1.球從100米高度掉落,每次落地反跳原高度的壹半,第10次落地

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;

}

運行測試:

  • 上一篇:web前端開發專業可以做什麽?
  • 下一篇:中國股市長期熊市的原因是什麽?
  • copyright 2024編程學習大全網