7-8 计算存款利息

本题目要求计算存款利息,计算公式为interest=money×(1+rate)year−money,其中interest为存款到期时的利息(税前),money是存款金额,year是存期,rate是年利率。

输入格式:

输入在一行中顺序给出三个正实数money、year和rate,以空格分隔。

输出格式:

在一行中按"interest = 利息"的格式输出,其中利息保留两位小数。

输入样例:

复制代码
1000 3 0.025

输出样例:

复制代码
interest = 76.89

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

我的答案:

C语言:

cpp 复制代码
# include<stdio.h>
# include<math.h>
int main()
{
	double interest,money,rate,year;
	scanf("%lf %lf %lf",&money,&year,&rate);
	interest=money*pow(1+rate,year)-money;
	printf("interest = %0.2lf",interest);
	return 0;
}

运行结果:

C++:

cpp 复制代码
#include <iostream>
using namespace std;
int main()
{
	double interest, money, rate, year;
	cin >> money >> rate >> year;
	interest = money * pow(1 + rate, year) - money;
	cout << "interest" << "=" << interest;
	
}

运行结果:

相关推荐
博客180013 小时前
酷宝的使用方法,超好用的免费界面库,C++、MFC可用
c++·mfc·界面库·库来帮·酷宝
郝学胜_神的一滴15 小时前
CMake 026:属性体系精讲、四大作用域全解 & 实战代码落地
c++·cmake
众少成多积小致巨1 天前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
clint4565 天前
C++进阶(1)——前景提要
c++
夜悊6 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴6 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0016 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾6 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
один but you6 天前
constexpr函数
c++
凡人叶枫6 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++