天天看點

c#基礎練習

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace 第四講1

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.Write(10 / 3 * 1.0);

            decimal PI = 3.14m;

            double pi = (double)PI;

            Console.ReadKey();

            int TX = 35;

            int KZ = 50;

            int sum = TX * 3 + KZ * 2;

            int pay = (int)(sum * 0.88);

           // 1.讓使用者輸入一個學生的姓名,以及三門功課的成績,之後通過程式計算出該學生的總成績和平均成績并輸入。Xxx的總成績為xxx,平均成績為xxx。

            //如果使用者輸入有錯怎麼防?

            try

            {

                Console.Write(" 輸入學生姓名:");

                string name = Console.ReadLine();//接收使用者輸入的内容

                Console.Write(" 輸入數學成績:");

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

                Console.Write(" 輸入國文成績:");

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

                Console.Write(" 輸入英語成績:");

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

                Console.WriteLine("{0}的三門課程總成績為{1},平均成績為{2}", name, math + chinese + english, (math + chinese + english) / 3);

            }

            catch {

                Console.WriteLine("您輸入的成績有誤,請如入100以内的正整數。");

           // 2.程式設計實作:使用者輸入一個天數(如46天),程式算出是幾周零幾天。并且在控制台輸出

            Console.WriteLine("請輸入天數:");

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

            int weeks = days / 7;

            int day = days % 7;

            Console.WriteLine("{0}天中有{1}星期零{2}天", days, weeks, day);

           // 3.程式設計實作使用者輸入的一個秒數(10765326878657秒),計算出是幾天幾個小時幾分鐘幾秒中,并在控制台輸入

            Console.WriteLine("請輸入秒數數:");

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

            int days = seconds / (3600 * 24);

            int mod = seconds % (3600 * 24);//得到出去上面天的秒數之外剩下的秒數

            int houres = mod / 3600;//等下的秒數中有多少個3600秒,就是有多少個小時。

            mod = mod % 3600;//得到剩下的秒數中出去上面的小時的秒數還剩多少秒。

            int min = mod / 60;//得到剩下的秒數中有多少個60秒,就是有多少分鐘。

            int second = mod % 60;

            Console.WriteLine("{0}秒中有{1}天,{2}小時,{3}分鐘,{4}秒。", seconds, days, houres, min, second);

            //4.使用計算機描述張三(20歲)比李四(18)小,這句話的結果。

            int zsAge = 20;

            int lsAge = 18;

            bool isRright = zsAge != lsAge;

            Console.WriteLine(isRright);         

繼續閱讀