美文网首页
第六课作业

第六课作业

作者: 是小凌哟 | 来源:发表于2018-11-07 21:42 被阅读0次

    Console.WriteLine("请输入一个年份"); int year = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("请输入一个月份");                     int month = Convert.ToInt32(Console.ReadLine());                     if (month >= 1 && month <= 12)                     {                         int day = 0;//存储天数                         switch (month)                         {                             case 1:                             case 3:                             case 5:                             case 7:                             case 8:                             case 10:                             case 12: day = 31;                                 break;                             case 2:                                 if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))                                 {                                     day = 29;                                 }                                 else                                 {                                     day = 28;                                 }                                 break;                             default: day = 30;                                 break;                         }//swich                         Console.WriteLine("{0}年{1}月有{2}天", year, month, day);                     }//if                     else                     {                         Console.WriteLine("月份必须在1~12月之间,程序退出!!!");                     }

        Console.WriteLine("请输入要计算的人的姓名");             string name = Console.ReadLine();             switch (name)             {                 case "老杨":                     Console.WriteLine("老杨上辈子是折翼的天屎");                     break;                 case "老苏":                     Console.WriteLine("老苏上辈子是老鸨子");                     break;                 case "老邹":                     Console.WriteLine("老邹上辈子是老苏手下的头牌");                     break;                 case "老虎":                     Console.WriteLine("上辈子被武松挂了");                     break;                 case "老牛":                     Console.WriteLine("上辈子是Cow");                     break;                 default:                     Console.WriteLine("上辈子没这个人");                     break;             }             Console.ReadKey();

    某人新开一个账户,输入开始存入的金额(本金)、年利率以及存款周期(年)。假定所有的利息收入都重新存入新户,请编写程序,计算并输出在存款周期中每年年终的账面金额。计算公式如下

    a=p(1+r)n

    p:本金,r:年利率,n:年数,a是在第n年年终的账面金额。

    Console.WriteLine("请输入你的本金");

    int p = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine("请输入年利率");

    double r = Convert.ToDouble(Console.ReadLine());

    Console.WriteLine("请输入存款周期(年)");

            int n = Convert.ToInt32(Console.ReadLine());

            double a = p * Math.Pow((1 + r), n);

            Console.WriteLine("您第{0}年的账面金额为{1}", n, a);

            Console.ReadKey();

    相关文章

      网友评论

          本文标题:第六课作业

          本文链接:https://www.haomeiwen.com/subject/uppbxqtx.html