使用 C 程式設計 EMI 計算器
提供給程式以特定值,此程式將開發一個 EMI 計算器以生成所需的輸出。EMI 代表等額月供。因此,此計算器將為使用者生成每月的 EMI 金額。
示例
Input-: principal = 2000 rate = 5 time = 4 Output-: Monthly EMI is= 46.058037
本程式中使用的公式為:
EMI:(P*R*(1+R)T)/(((1+R)T)-1)
其中:
P 表示貸款金額或本金金額。
R 表示每月利率
T 表示貸款期限,以年為單位
下面使用的方法如下:
- 輸入浮點變數中的本金、利率和時間
- 應用公式計算 EMI 金額
- 列印 EMI 金額
演算法
Start Step 1 -> Declare function to calculate EMI float calculate_EMI(float p, float r, float t) float emi set r = r / (12 * 100) Set t = t * 12 Set emi = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1) Return emi Step 2 -> In main() Declare variable as float principal, rate, time, emi Set principal = 2000, rate = 5, time = 4 Set emi = calculate_EMI(principal, rate, time) Print emi Stop
示例
#include <math.h>
#include <stdio.h>
// Function to calculate EMI
float calculate_EMI(float p, float r, float t){
float emi;
r = r / (12 * 100); // one month interest
t = t * 12; // one month period
emi = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1);
return (emi);
}
int main(){
float principal, rate, time, emi;
principal = 2000;
rate = 5;
time = 4;
emi = calculate_EMI(principal, rate, time);
printf("
Monthly EMI is= %f
", emi);
return 0;
}輸出
Monthly EMI is= 46.058037
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP