29495人加入学习
(81人评价)
C#编程-第一季-编程基础-宇宙最简单2021最新版

制作完成于2021年10月10日,使用Visual Studio 2019

价格 免费

            //输⼊⼀个正整数n,输出n层的菱形。

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

            for (int i = 1; i <= 2*n-1; i++)//直接列出总行数 用if区分上下两边
            {
                if (i <= n)//上半边
                {
                    for (int j = 0; j < n - i; j++)//n-i 个空白
                    {
                        Console.Write(" ");
                    }
                    for (int j = 0; j < 2 * i - 1; j++)//2*i-1 个*
                    {
                        Console.Write("*");
                    }
                }
                if (i > n)//下半边
                {
                    for (int j = 0; j < i-n; j++)//i-n 个空白
                    {
                        Console.Write(" ");
                    }
                    for (int j = 2*(2*n-i)-1; j>0 ; j--)//2*i-1 个*
                    {
                        Console.Write("*");
                    }
                }

                Console.WriteLine();//换行
            }
            Console.ReadKey();

 

[展开全文]

1:3,6

2:3

3: Console.WriteLine("*\n**\n***\n****\n*\n*\n*");

4: Console.WriteLine("   *\n  ***\n *****\n*******\n   *\n   *\n   *");

5:d

6: Console.WriteLine("SIKI说:\"what is \\n\"");

新建项目002.设为启动项目

[展开全文]

转译字符:

\n :换行的意思

\t :制表符,vs内为四个空格

[展开全文]
//✋假设有个隧道,隧道以字符 ‘#’ 结束,挖矿的过程中,会遇到钻⽯ ‘*’ 和美⾦ ‘1’ ~ ‘9’ ,
//让矿⼯⼩六挖到隧道的尽头,假设每个钻⽯价值500美⾦,统计⼩六挖到了价值多少美⾦的收获?
//样例输⼊ ka4d*s6kkl8s*d9fyo#
//样例输出 1027

            char a;  //定义字符‘a’
            int r = 0; //定义最后的金额为r
            do
            {
                a = (char)Console.Read();  //获取用户输入的字符
                if (a=='*')  //判断输入的是否为‘*’ 
                {
                    r += 500;  //输入的为‘*’则r+500
                }
                else if (a >= '0' && a <= '9')  //判断输入的是否为字符数字
                {
                    int temp = a - '0';  //字符数字减去字符‘0’ 得到的就是本身数值
                    r = r + temp;  //将结果相加
                }
            } while (a != '#');  //当输入的是‘#’ 结束循环
            Console.WriteLine(r);
            Console.ReadKey();

 

[展开全文]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 字符串的读取
{
    class Program
    {
        static void Main(string[] args)
        {
            //数字和字符混合在⼀起了,作为⼀个优秀的挖掘⼈员,把输⼊的数字挖出来,并计算这些数字的和,并输出。输⼊以 @作为结束。
            //样例输⼊ 23a34b34@    样例输出 19

            char a;//定义字符
            int sum = 0;//定义字符串的数字之和为sum
            do//do...while循环 先执行用户输入的代码
            {
                a = (char)Console .Read ();//读取用户输入的字符
                if (a >= '0' && a <= '9')//判断输入的字符是否是数字  每个字符数字都有对应的数字  在范围内就是数字
                {
                    int temp = a - '0';//如果是字符数字,减去字符‘0’对应的数字就是本身的数值
                    sum += temp;//将数字相加并存储到sum
                }
               
            }while (a!='@');//当输入的字符不是‘@’时  执行循环
            Console.WriteLine(sum);
            Console.ReadKey();







        }
    }
}

 

[展开全文]

引入命名空间system;

自己的命名空间

{

自己的类

{

自己的方法//包含以下

{

    别人的类//位于system下面的.别人的方法(内容)

}

 

注释一般在方法和类的上方

单行注释:// 加在代码前后

多行注释:

/*dd

dsd

1*/

 

注释快捷键:ctrl k + ctrl c

取消注释快捷键:ctrl k + ctrl u

 

[展开全文]
using System;

namespace _026_循环嵌套
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1 = Convert.ToInt32(Console.ReadLine());
            int num2 = Convert.ToInt32(Console.ReadLine());
            int min = num1;
            if (num2 < min)
            {
                min = num2;
            }
            for (int i = min; i > 0; i--)
            {
                if (num1 % i == 0 && num2 % i == 0)
                {
                    Console.WriteLine("最大公约数:" + i);
                    break;
                }
            }
        }
    }
}

 

[展开全文]
using System;

namespace _026_循环嵌套
{
    class Program
    {
        static void Main(string[] args)
        {
            //for (int i = 1; i <= 9; i++)
            //{
            //    //i 右乘数    左乘数1-i
            //    for (int j = 1; j <= i; j++)
            //    {
            //        Console.Write("{0}x{1}={2,2} ", j, i, i * j);
            //    }
            //    Console.WriteLine();
            //}


            ////x y z 公鸡1-33 母鸡1-20 小鸡1-50
            //for (int x = 1; x <= 100 / 3; x++)
            //{
            //    for (int y = 1; y < 100 / 5; y++)
            //    {
            //        for (int z = 1; z < 100 / 2; z++)
            //        {
            //            //是否花费了100文,100只鸡
            //            if (3 * x + 5 * y + 2 * z == 100)
            //            {
            //                Console.WriteLine("公鸡{0}, 母鸡{1}, 小鸡{2}", x, y, z);
            //            }
            //        }
            //    }
            //}


            //自写
            //百元买百鸡 公鸡3元一只,母鸡5元一只,小鸡3只一元
            for (int x = 0; x <= 100 / 3; x++)//公鸡最多33只
            {
                for (int y = 0; y <= 100 / 5; y++)//母鸡最多20只
                {
                    for (int z = 0; z < 100; z += 3)//z+=3是因为小鸡3元一只,凑整,这样没有必要计算小数点
                    {
                        //是否 100只鸡,且 花费了100元
                        if ((x + y + z == 100) && (3 * x + 5 * y + z / 3 == 100))
                        {
                            Console.WriteLine("公鸡:{0,2}, 母鸡:{1,2}, 小鸡:{2}", x, y, z);
                        }
                    }
                }
            }

        }
    }
}

 

[展开全文]
using System;

namespace _026_循环嵌套
{
    class Program
    {
        static void Main(string[] args)
        {
            //int n = Convert.ToInt32(Console.ReadLine());
            //for (int i = 1; i <= n; i++)
            //{
            //    for (int j = 0; j < i - 1; j++)
            //    {
            //        Console.Write(" ");
            //    }
            //    for (int j = 0; j < n; j++)
            //    {
            //        Console.Write("*");
            //    }
            //    Console.WriteLine();
            //}


            //int n = Convert.ToInt32(Console.ReadLine());
            //for (int i = 1; i <= n; i++)
            //{
            //    // n-i个空格  i个*
            //    for (int j = 0; j < n - i; j++)
            //    {
            //        Console.Write(" ");
            //    }
            //    for (int j = 0; j < i; j++)
            //    {
            //        Console.Write("*");
            //    }
            //    Console.WriteLine();
            //}


            //int n = Convert.ToInt32(Console.ReadLine());
            //for (int i = 1; i <= n; i++)
            //{
            //    // n-i 2*i-1
            //    for (int j = 0; j < n - i; j++)
            //    {
            //        Console.Write(" ");
            //    }
            //    for (int j = 0; j < 2 * i - 1; j++)
            //    {
            //        Console.Write("*");
            //    }
            //    Console.WriteLine();
            //}


            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= n; i++)
            {
                // n-i 2*i-1
                for (int j = 0; j < n - i; j++)
                {
                    Console.Write(" ");
                }
                for (int j = 0; j < 2 * i - 1; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            //n-1总行数
            for (int i = 1; i <= n - 1; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    Console.Write(" ");
                }
                //*
                //n-1-i+1 = n-i  *2-1
                for (int j = 0; j < 2 * (n - i) - 1; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
    }
}

 

[展开全文]
using System;

namespace _026_循环嵌套
{
    class Program
    {
        static void Main(string[] args)
        {
            //int n = Convert.ToInt32(Console.ReadLine());
            //for (int i = 1; i < n + 1; i++)
            //{
            //    //i=1  1    i=2  2    i=3  3
            //    for (int j = 0; j < i; j++)
            //    {
            //        Console.Write("*");
            //    }
            //    Console.WriteLine();
            //}


            //int n = Convert.ToInt32(Console.ReadLine());
            //for (int i = 1; i < n + 1; i++)
            //{
            //    //行号-1个*
            //    for (int j = 0; j < i - 1; j++)
            //    {
            //        Console.Write(" ");
            //    }
            //    Console.WriteLine("*");
            //}


            //for (int i = 100; i > 0; i--)
            //{
            //    Console.WriteLine(i);
            //}

            int n = Convert.ToInt32(Console.ReadLine());
            // n~1
            for(int i = n; i > 0; i--)
            {
                for(int j = 0; j < i - 1; j++)
                {
                    Console.Write(" ");
                }
                Console.WriteLine("*");
            }
        }
    }
}

 

[展开全文]
using System;

namespace _026_循环嵌套
{
    class Program
    {
        static void Main(string[] args)
        {
            //for (int i = 0; i < 4; i++)
            //{
            //    for(int j = 0; j < 10; j++)
            //    {
            //        Console.Write("*");// i=0  j=0~9  i=1
            //    }
            //    Console.WriteLine();
            //}

            int n = Convert.ToInt32(Console.ReadLine());
            int m = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
    }
}

 

[展开全文]
using System;

namespace _025_循环中的continue
{
    class Program
    {
        static void Main(string[] args)
        {
            //for (int i = 1; i <= 100; i++)
            //{
            //    if (i % 2 == 1)
            //    {
            //        Console.WriteLine(i);
            //    }
            //}

            // continue;
            // break;
            for (int i = 1; i <= 100; i++)
            {
                if (i % 2 == 0)
                {
                    continue;//中止当前循环,继续下次循环
                    //break;
                }
                Console.WriteLine(i);
            }
        }
    }
}

 

[展开全文]
using System;

namespace _024_字符读取和编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //char c;// '0' -- 55  '9' --
            //int sum = 0;
            //do
            //{
            //    c = (char)Console.Read();
            //    if (c >= '0' && c <= '9')
            //    {
            //        int number = c - '0';
            //        sum += number;
            //    }
            //    else if (c == '*')
            //    {
            //        sum += 500;
            //    }
            //} while (c != '#');
            //Console.WriteLine(sum);
            //31dj*31#
            //508


            //int n = Convert.ToInt32(Console.ReadLine());
            //int count = 0;
            //string str = "";
            //for (int i = 1; i <= n; i++)
            //{
            //    if (n % i == 0)
            //    {
            //        count++;
            //        str += i + " ";
            //    }
            //}
            //Console.WriteLine(count);
            //Console.WriteLine(str);
            //9
            //1 3 9


            int n = Convert.ToInt32(Console.ReadLine());
            int count = 0;
            for (int i = 1; i <= n; i++)
            {
                if (n % i == 0)
                {
                    count++;
                }
            }
            if (count == 2)
            {
                Console.WriteLine("yes");
            }
            else
            {
                Console.WriteLine("no");
            }
        }
    }
}

 

[展开全文]
using System;

namespace _024_字符读取和编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //Convert.ToInt32(Console.ReadLine());
            //数字类型 字符串
            // a 换行
            //char a = (char)Console.Read();
            //char b = (char)Console.Read();

            //Console.WriteLine("-----------");
            //Console.WriteLine(a);
            //Console.WriteLine(b);
            //char c = (char)Console.Read();
            //Console.WriteLine(c);

            char c;// '0' -- 55  '9' --
            int sum = 0;
            do
            {
                c = (char)Console.Read();
                if (c >= '0' && c <= '9')
                {
                    int number = c - '0';
                    sum += number;
                }
            } while (c != '@');
            Console.WriteLine(sum);
        }
    }
}

 

[展开全文]
using System;

namespace _023_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int tempn = n;
            int number = 0;
            // 3617
            // 7 1 6 3
            // 7*10 10
            //71*10 710
            //7160
            //7163
            while (tempn != 0)//从低位到高位
            {
                int i = tempn % 10;
                number *= 10;
                number += i;
                //i=7  number=7
                //i=1 70 71
                tempn /= 10;
            }
            if (number == n)
            {
                Console.WriteLine("yes");
            }
            else
            {
                Console.WriteLine("no");
            }
        }
    }
}

 

[展开全文]
using System;

namespace _022_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            //标志位,标志是否达到了某个条件
            bool yudao = false;// 默认还没有遇到第一个非0数字
            while (n != 0)//从低位到高位遍历
            {
                int i = n % 10;// 23407800    i= 0 0 8 7 0 4 3 2
                //判断是否遇到了第一个非0数字
                //    不需要去掉0
                //还没有遇到第一个非0数字
                //    需要去掉0
                if (yudao==false)//还没有遇到第一个非0数字
                {
                    if (i != 0)//i=8
                    {
                        Console.Write(i);
                        yudao = true;
                    }
                }
                else //i=7
                {
                    Console.Write(i);
                }
                n /= 10;
            }
        }
    }
}

 

[展开全文]
using System;

namespace _022_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //三位水仙花数
            //for (int i = 100; i <= 999; i++)
            //{
            //    int ge = i % 10;
            //    int shi = (i / 10) % 10;
            //    int bai = i / 100;
            //    if (i == bai * bai * bai + shi * shi * shi + ge * ge * ge)
            //    {
            //        Console.WriteLine(i);
            //    }
            //}
            // 153, 370, 371, 407


            //2325
            //5 232
            //2 23
            //3 2
            //2 0
            //int n = Convert.ToInt32(Console.ReadLine());
            //while (n != 0)
            //{
            //    int ge = n % 10;
            //    Console.WriteLine(ge);
            //    n /= 10;
            //}


            int n = Convert.ToInt32(Console.ReadLine());
            int sum = 0;
            int cheng = 1;// 1 10 100 1000
            while (n != 0)
            {
                int i = n % 10;//i就是遍历各个位上的数字
                if (i != 0)
                {
                    i *= cheng;//ge 1*
                    sum += i;
                    cheng *= 10;
                }
                n /= 10;
            }
            Console.WriteLine(sum);
        }
    }
}

 

[展开全文]
using System;

namespace _022_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //int k = Convert.ToInt32(Console.ReadLine());
            //// n 1
            //double sn = 0;
            //int n = 0;
            //while (sn <= k)
            //{
            //    n++;
            //    sn += 1.0 / n;
            //}
            //Console.WriteLine(n);
            ////k=2
            ////1+1/2+1/3+1/4=2.08333


            //double x = Convert.ToInt32(Console.ReadLine());
            //int n = Convert.ToInt32(Console.ReadLine());
            //for (int i = 0; i < n; i++)
            //{
            //    x *= 1.001;
            //}
            //Console.WriteLine(x);


            // R M Y
            int r = Convert.ToInt32(Console.ReadLine());
            int m = Convert.ToInt32(Console.ReadLine());
            int y = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < y; i++)
            {
                m = (int)(m * ((r / 100.0) + 1));
            }
            Console.WriteLine(m);
        }
    }
}

 

[展开全文]
using System;

namespace _022_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //int a = Convert.ToInt32(Console.ReadLine());
            //int n = Convert.ToInt32(Console.ReadLine());
            //int result = 1;
            //for (int i = 0; i < n; i++)
            //{
            //    result *= a;// 1 *a*a*a
            //}
            //Console.WriteLine(result);


            // 6   1*2*3*4*5
            //int n = Convert.ToInt32(Console.ReadLine());
            //int result = 1;
            //for(int i = 1; i <= n; i++)
            //{
            //    result *= i;
            //}
            //Console.WriteLine(result);

            int q = Convert.ToInt32(Console.ReadLine());
            int n = Convert.ToInt32(Console.ReadLine());
            int temp = 1;
            int sum = 1;
            for(int i = 1; i <= n; i++)
            {
                //q^n
                temp *= q;
                sum += temp;
            }
            // q=3 n=3
            // 1+3+9+27=40
            Console.WriteLine(sum);
        }
    }
}

 

[展开全文]
using System;

namespace _022_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            double high = n;
            for (int i = 0; i < 10; i++)
            {
                high /= 2;
            }
            Console.WriteLine("第10次落地后,会反弹的高度是:" + high);
            //  1 --- 2n
            //  2 --- n
            //  3 --- n/2
            // 10 --- d(9)/2
            double distance = 2 * n;
            double sum = n;
            for (int i = 0; i < 9; i++)
            {
                distance /= 2;
                sum += distance;
            }
            Console.WriteLine("第10次落地后经过了多少米:" + sum);
        }
    }
}

 

[展开全文]

授课教师

加我的QQ问问题:804632564

课程特色

下载资料(1)
视频(118)
图文(2)