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;
	
}

运行结果:

相关推荐
端平入洛1 天前
delete又未完全delete
c++
端平入洛2 天前
auto有时不auto
c++
哇哈哈20213 天前
信号量和信号
linux·c++
多恩Stone3 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马3 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝3 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode
weiabc3 天前
printf(“%lf“, ys) 和 cout << ys 输出的浮点数格式存在细微差异
数据结构·c++·算法
问好眼3 天前
《算法竞赛进阶指南》0x01 位运算-3.64位整数乘法
c++·算法·位运算·信息学奥赛
yyjtx3 天前
DHU上机打卡D31
开发语言·c++·算法
czxyvX3 天前
020-C++之unordered容器
数据结构·c++