计算复利率小程序(C#版)
2007-12-02 03:08
218 查看
程序代码如下(有许多需要修改的地方没有做好):
using System;
using System.Collections.Generic;
using System.Text;
namespace interest
{
// 计算复利率;
class interest
{
static void Main(string[] args)
{
// 定义变量;
decimal acount=0.0M; // 本金和利息;
decimal principal; // 本金;
double rate; // 年利率;
int year; // 第几年;
// 显示用户界面;
Console.WriteLine();
Console.WriteLine("欢迎使用复利率计算系统!");
// 提示用户输入参数初始化变量;
Console.WriteLine("");
Console.Write("请您输入本金金额: ");
principal = Convert.ToDecimal(Console.ReadLine());
Console.Write("请您输入年利率: ");
rate = Convert.ToDouble(Console.ReadLine());
Console.Write("请您输入计算年数: ");
year = Convert.ToInt32(Console.ReadLine());
// 显示结果表头;
Console.WriteLine("");
Console.WriteLine("=================计算结果===================");
Console.WriteLine("");
Console.WriteLine("{0,4} {1,15} {2,15}","第n年","年利","本金+年利");
// 逐条打印输出计算结果;
for (int index = 1; index <= year; index++)
{
acount = principal *((decimal) Math.Pow(1 + rate, index));
Console.WriteLine("{0,6} {1,16:C} {2,18:C}",index,acount-principal,acount);
} // end for;
} // end Main;
} // end class;
} // end namespace;
输出为:
欢迎使用复利率计算系统!
请您输入本金金额: 1000
请您输入年利率: 0.05
请您输入计算年数: 10
=================计算结果===================
第n年 年利 本金+年利
1 ¥50.00 ¥1,050.00
2 ¥102.50 ¥1,102.50
3 ¥157.63 ¥1,157.63
4 ¥215.51 ¥1,215.51
5 ¥276.28 ¥1,276.28
6 ¥340.10 ¥1,340.10
7 ¥407.10 ¥1,407.10
8 ¥477.46 ¥1,477.46
9 ¥551.33 ¥1,551.33
10 ¥628.89 ¥1,628.89
(小弟刚学C#,请勿见效,有劳各位仁兄多多指教!)
using System;
using System.Collections.Generic;
using System.Text;
namespace interest
{
// 计算复利率;
class interest
{
static void Main(string[] args)
{
// 定义变量;
decimal acount=0.0M; // 本金和利息;
decimal principal; // 本金;
double rate; // 年利率;
int year; // 第几年;
// 显示用户界面;
Console.WriteLine();
Console.WriteLine("欢迎使用复利率计算系统!");
// 提示用户输入参数初始化变量;
Console.WriteLine("");
Console.Write("请您输入本金金额: ");
principal = Convert.ToDecimal(Console.ReadLine());
Console.Write("请您输入年利率: ");
rate = Convert.ToDouble(Console.ReadLine());
Console.Write("请您输入计算年数: ");
year = Convert.ToInt32(Console.ReadLine());
// 显示结果表头;
Console.WriteLine("");
Console.WriteLine("=================计算结果===================");
Console.WriteLine("");
Console.WriteLine("{0,4} {1,15} {2,15}","第n年","年利","本金+年利");
// 逐条打印输出计算结果;
for (int index = 1; index <= year; index++)
{
acount = principal *((decimal) Math.Pow(1 + rate, index));
Console.WriteLine("{0,6} {1,16:C} {2,18:C}",index,acount-principal,acount);
} // end for;
} // end Main;
} // end class;
} // end namespace;
输出为:
欢迎使用复利率计算系统!
请您输入本金金额: 1000
请您输入年利率: 0.05
请您输入计算年数: 10
=================计算结果===================
第n年 年利 本金+年利
1 ¥50.00 ¥1,050.00
2 ¥102.50 ¥1,102.50
3 ¥157.63 ¥1,157.63
4 ¥215.51 ¥1,215.51
5 ¥276.28 ¥1,276.28
6 ¥340.10 ¥1,340.10
7 ¥407.10 ¥1,407.10
8 ¥477.46 ¥1,477.46
9 ¥551.33 ¥1,551.33
10 ¥628.89 ¥1,628.89
(小弟刚学C#,请勿见效,有劳各位仁兄多多指教!)
相关文章推荐
- C#计算程序运行时间的三种方法
- C#行列式计算程序
- C#计算程序运行时间
- C# Mandelbrot和Julia分形图像生成程序更新到2010-9-14版 支持多线程计算 多核处理器
- c# 计算程序执行时间
- c# 计算程序执行时间方法
- 计算程序运行时间C#
- c#中精确计算程序执行时间
- C#计算程序执行过程花费时间的方法
- c#常用程序运行时间计算方法
- C#计算一段程序运行时间的三种方法
- C#计算程序执行速度
- 【转】C# 计算程序运行时间
- C# 计算一段程序运行时间
- C#计算一段程序运行时间的三种方法
- C#计算程序的运行时间
- 编写一个C#程序,要求定义一个行数和列数相等的二维数组, 并执行初始化,然后计算并输出数组两条对角线上的元素之和。
- C#计算程序的运行时间
- C#计算一段程序的运行时间
- c#开发-计算一段程序运行的时间