返回列表 發帖
哈哈 我是第一個寫好ㄉ!!
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. float power(float x , int n){
  5.     float num = x;
  6.     for(int i = 1; i < n; i++){
  7.         num = num * x;
  8.     }
  9.     return num;
  10. }
  11. int main(void){
  12.    
  13.     float p , r , t;
  14.     int n;
  15.     cout << "請輸入本金" << endl;
  16.     cin >> p;
  17.     cout << "請輸入年利率" << endl;
  18.     cin >> r;
  19.     cout << "請輸入存款期數" << endl;
  20.     cin >> n;
  21.     r = r + 1;
  22.     t = p * power(r , n);
  23.     cout << "本利和為 " << t << endl;
  24.    
  25.     system("pause");
  26.     return 0;
  27. }
複製代碼

TOP

返回列表