返回列表 發帖
  1. #include<iostream>
  2. using namespace std;
  3. float power(float x,int n){
  4.     float num=x;
  5.     for(int i=1;i<n;i++){
  6.        num=num*x;     
  7.     }      
  8.     return num;
  9. }
  10. int main(){
  11.     double total;
  12.     total=0;
  13.     for(int i=1;i<=10;i++){  
  14.         total=total+ 1/power(2,i);
  15.     }
  16.    
  17.    cout << total << endl;
  18.   system("Pause");
  19.   return 0;
  20. }
  21.   
複製代碼
張雅淳

TOP

返回列表