C#体验流程控制(一)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace riqi
{
    class Program
    {
        static void Main(string[] args)
        {
            int y;
            int m;
            int d;
            Console.WriteLine("请输入年月日:");
            y = Convert.ToInt32(Console.ReadLine());
            m = Convert.ToInt32(Console.ReadLine());
            d = Convert.ToInt32(Console.ReadLine());
            if (m == 1 || m == 2)
            {
                m += 12;
                y--;
            }
            int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 -y / 100 + y / 400 + 1) % 7;

            string weeking = "";
            switch (week)
            {
                case 0: weeking = "星期日"; break;
                case 1: weeking = "星期一"; break;
                case 2: weeking = "星期二"; break;
                case 3: weeking = "星期三"; break;
                case 4: weeking = "星期四"; break;
                case 5: weeking = "星期五"; break;
                case 6: weeking = "星期六"; break;
                default: break;

            }
            Console.WriteLine(weeking);
        }
    }
}

流程控制:顺序,选择,循环结构。

算法概念的理解

数据结构+算法=程序

认识流程图

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace hailun
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = Convert.ToDouble(Console.ReadLine());
            double b = Convert.ToDouble(Console.ReadLine());
            double c = Convert.ToDouble(Console.ReadLine());
            double p = (a + b + c) / 2;
            double s = Math.Sqrt(p*(p-a)*(p-b)*(p-c));

            Console.WriteLine("三角形的面积为{0:f2}",s);
        }
    }
}

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shuru
{
    class Program
    {
        static void Main(string[] args)
        {
            double r;
            r = Convert.ToDouble(Console.ReadLine());
            double b = Math.Sqrt(r/2);
            double a = 2 * b;
            Console.WriteLine(a);

        }
    }
}

  计算一个学生数学,语文,英语三门课程的平均成绩

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PingJun
{
    class Program
    {
        static void Main(string[] args)
        {
            double a,b,c,d;
            a = Convert.ToDouble(Console.ReadLine());
            b = Convert.ToDouble(Console.ReadLine());
            c = Convert.ToDouble(Console.ReadLine());
            d = (a + b + c) / 3;
            Console.WriteLine("平均成绩为{0:f2}",d);
        }
    }
}

  

 

posted on 2013-04-27 20:23  杨柳清枫2012  阅读(201)  评论(0)    收藏  举报

导航