#include <iostream> #include <cmath> using namespace std; int main() { double deposit = 100.0; double monthly_interest_rate = 0.00417; double account_balance = deposit; for (int i = 0; i < 6; i++) { account_balance = (account_balance + deposit) * (1 + monthly_interest_rate); } cout << "After 6 months, the account balance will be: $" << round(account_balance * 100) / 100 << endl; return 0; }将该代码改写为c语言
时间: 2023-06-26 14:06:09 浏览: 89
#include_iostream.h_
4星 · 用户满意度95%
#include <stdio.h>
#include <math.h>
int main() {
double deposit = 100.0;
double monthly_interest_rate = 0.00417;
double account_balance = deposit;
for (int i = 0; i < 6; i++) {
account_balance = (account_balance + deposit) * (1 + monthly_interest_rate);
}
printf("After 6 months, the account balance will be: $%.2f\n", round(account_balance * 100) / 100);
return 0;
}
注意:C语言中没有自动类型推导,需要在变量声明时指明数据类型。此外,C语言中的输出需要使用printf函数。
阅读全文