哈哈 我是第一個寫好ㄉ!!- #include <iostream>
- #include <cstdlib>
- using namespace std;
- float power(float x , int n){
- float num = x;
- for(int i = 1; i < n; i++){
- num = num * x;
- }
- return num;
- }
- int main(void){
-
- float p , r , t;
- int n;
- cout << "請輸入本金" << endl;
- cin >> p;
- cout << "請輸入年利率" << endl;
- cin >> r;
- cout << "請輸入存款期數" << endl;
- cin >> n;
- r = r + 1;
- t = p * power(r , n);
- cout << "本利和為 " << t << endl;
-
- system("pause");
- return 0;
- }
複製代碼 |