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

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

价格 免费
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);
        }
    }
}

 

[展开全文]
using System;

namespace _022_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //int n = Convert.ToInt32(Console.ReadLine());
            //int sum = n;
            //while (n != 0)
            //{
            //    n = Convert.ToInt32(Console.ReadLine());
            //    sum += n;
            //}
            //Console.WriteLine(sum);


            int n = 0;
            int sum = 0;
            do
            {
                n = Convert.ToInt32(Console.ReadLine());
                sum += n;
            } while (n != 0);
            Console.WriteLine(sum);
        }
    }
}

 

[展开全文]
using System;

namespace _021_变量的作用域
{
    class Program
    {
        static void Main(string[] args)
        {
            // if while for
            // 局部变量
            //int a = 10;
            //Console.WriteLine(a);
            //if (true)
            //{
            //    int b = 20;
            //    Console.WriteLine(a);
            //    Console.WriteLine(b);
            //    if (true)
            //    {
            //        int c = 30;
            //        Console.WriteLine(a);
            //        Console.WriteLine(b);
            //        Console.WriteLine(c);
            //    }
            //}
            ////Console.WriteLine(b);//报错


            int a = 10;
            Console.WriteLine(a);
            while (true)
            {
                int b = 10;
                Console.WriteLine(b);
            }
            //Console.WriteLine(b);//报错

            for(int j = 0; j < 10; j++)
            {

            }
            for (int j = 0; j < 10; j++)
            {

            }
            //Console.WriteLine(j);//报错

            //同一作用域内变量名不能重名
            //父作用域与子作用域,可以访问父作用域的变量,但是父作用域不能访问子作用域里面的变量。
        }
    }
}

 

[展开全文]
using System;

namespace _020_for循环
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;//true
            //break;  switch也有brak
            for (; ;)
            {
                Console.WriteLine(i);
                i++;
                if (i > 10)
                {
                    break;//跳出离它最近的循环
                }
            }

            //for(; ; ) { }
        }
    }
}

 

[展开全文]
using System;

namespace _021_do_while循环
{
    class Program
    {
        static void Main(string[] args)
        {
            //while (true)
            //{
            //}

            // 1-10
            int i = 1;
            //do
            //{
            //    Console.WriteLine(i);
            //    i++;
            //} while (i < 11);

            //while (i < 11)
            //{
            //    Console.WriteLine(i);
            //    i++;
            //}


            //while (i < 0)
            //{
            //    Console.WriteLine("i < 0");
            //}

            do
            {
                Console.WriteLine("i < 0");
            } while (i < 0);

            // do while会先执行一次循环体,然后再判断
            //区别:当首次进入循环不满足条件表达式的时候,do while会执行一次循环体,while一次都不会执行。
            //其他情况,do while和while没有区别。
        }
    }
}

 

[展开全文]
using System;

namespace _020_for循环
{
    class Program
    {
        static void Main(string[] args)
        {
            //数组
            //for (int i = 0; i < 20; i++)
            //{
            //    Console.Write("*");
            //}


            //int sum = 0;
            //for (int i = 1; i < 101; i++)
            //{
            //    sum += i;
            //}
            //Console.Write(sum);


            //for (int i = 1; i < 101; i++)
            //{
            //    if (i % 2 == 0)
            //    {
            //        Console.WriteLine(i);
            //    }
            //}


            //int n = Convert.ToInt32(Console.ReadLine());
            //int m = Convert.ToInt32(Console.ReadLine());
            //int sum = 0;
            //for(int i = n; i <= m; i++)
            //{
            //    if (i % 17 == 0)
            //    {
            //        sum += i;
            //    }
            //}
            //Console.Write(sum);


            int n = Convert.ToInt32(Console.ReadLine());
            int m = Convert.ToInt32(Console.ReadLine());
            string ji = "";
            string ou = "";
            for (int i = n; i <= m; i++)
            {
                if (i % 2 == 1)
                {
                    ji += i + " ";
                }
                else
                {
                    ou += i + " ";
                }
            }
            Console.WriteLine(ji);
            Console.WriteLine(ou);
        }
    }
}

 

[展开全文]
using System;

namespace _020_for循环
{
    class Program
    {
        static void Main(string[] args)
        {
            //int i = 0;
            //while (i < 10)
            //{
            //    Console.WriteLine(i);
            //    i++;
            //}


            //for (int i = 0; i < 10; i++)
            //{
            //    Console.WriteLine(i);
            //}


            for (int i = 1; i < 11; i++)
            {
                Console.WriteLine(i);
            }

            for (int i = 1; i <= 10; i++)
            {
                Console.WriteLine(i);
            }
        }
    }
}

 

[展开全文]
using System;

namespace _019_while循环_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //int number = 80000;
            //int year = 2006;
            //while (number < 200000)
            //{
            //    number = (int)(number * 1.25);//增加了一年
            //    year++;
            //}
            //Console.WriteLine(year);


            //int n = Convert.ToInt32(Console.ReadLine());
            //int i = 1;
            //int sum = 0;
            //while (i < n + 1)
            //{
            //    //int year = Convert.ToInt32(Console.ReadLine());
            //    //sum += year;
            //    sum += Convert.ToInt32(Console.ReadLine());
            //    i++;
            //}
            //double ave = 1.0 * sum / n;
            //// 4.5342 100 int 453
            //ave = ((int)(ave * 100)) / 100.0;
            //Console.WriteLine(ave);


            //Console.WriteLine(1);
            //Console.Write(2);
            //Console.Write(3);
            //Console.WriteLine(4);
            ////1
            ////234
            ////


            int n = Convert.ToInt32(Console.ReadLine());
            int i = 1;
            while (i < n + 1)
            {
                Console.Write(i + " ");
                i++;
            }

        }
    }
}

 

[展开全文]
using System;

namespace _019_while循环_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int j = 0;
            while (n != 1)
            {
                if (n % 2 == 1)
                {
                    n = 3 * n + 1;
                }
                else
                {
                    n /= 2;
                }
                j++;
                Console.WriteLine("变换后的值为:" + n);
            }
            Console.WriteLine(" 变换的次数为:" + j);
        }
    }
}

 

[展开全文]
using System;

namespace _018_循环语句_while循环
{
    class Program
    {
        static void Main(string[] args)
        {
            //int n = Convert.ToInt32(Console.ReadLine());
            //int i = 1;
            //int sum = 0;
            //while (i < n + 1)
            //{
            //    sum += i;
            //    i++;
            //}
            //Console.WriteLine(sum);


            //int i = 1;
            //while (i < 101)
            //{
            //    // 1-100
            //    if (i % 2 == 0)
            //    {
            //        Console.WriteLine(i);
            //    }
            //    i++;
            //}


            // 10 15
            //int i = 10;
            //while (i < 16)
            //{
            //    Console.WriteLine(i);
            //    i++;
            //}

            int n1 = Convert.ToInt32(Console.ReadLine());
            int n2 = Convert.ToInt32(Console.ReadLine());

            int i = n1;
            while (i < n2 + 1)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine(i);
                }
                i++;
            }

        }
    }
}

 

[展开全文]
using System;

namespace _018_循环语句_while循环
{
    class Program
    {
        static void Main(string[] args)
        {
            // 1-100
            // 100-1
            //int i = 100;
            //while (i > 0)
            //{
            //    Console.WriteLine(i);
            //    i--;
            //}
            //i=0

            //int i = 101;
            //while (i > 1)
            //{
            //    i--;
            //    Console.WriteLine(i);
            //}


            // 1+2+3...n
            // 1+2+3...100

            int i = 1;
            int sum = 0;
            while (i < 101)
            {
                // 1-100  sum=sum+i;
                sum += i;
                i++;
            }
            Console.WriteLine(sum);

        }
    }
}

 

[展开全文]
using System;

namespace _018_循环语句_while循环
{
    class Program
    {
        static void Main(string[] args)
        {
            //int i = 1;
            //while (i < 11)
            //{
            //    Console.WriteLine(i);
            //    i++;
            //}

            // 1-10
            //int i = 0;
            //while (i < 10)
            //{
            //    i++;
            //    Console.WriteLine(i);
            //}


            //int i = 1;
            //while (i < 1001)
            //{
            //    Console.WriteLine(i);
            //    i++;
            //}


            int HP = 100;
            while (HP > 0)
            {
                HP -= 3;
                Console.WriteLine("HP: " + HP);
            }
        }
    }
}

 

[展开全文]
using System;

namespace _018_循环语句_while循环
{
    class Program
    {
        static void Main(string[] args)
        {
            // Write  WriteLine
            //Console.WriteLine("1");
            //Console.WriteLine("2");
            //Console.WriteLine("3");
            //Console.WriteLine("4");
            //Console.WriteLine("5");
            //Console.WriteLine("6");
            //Console.WriteLine("7");
            //Console.WriteLine("8");
            //Console.WriteLine("9");

            // 1-10
            // true false
            //while (true)
            //{
            //    Console.WriteLine("while循环体");
            //}

            // 1-10
            int i = 1;
            //while (true)
            //{
            //    Console.WriteLine(i);
            //    i++;
            //}

            while (i < 11)
            {
                Console.WriteLine(i);
                i++;
            }
            //i=11
            Console.WriteLine("while后:" + i);

            //当while不满足条件的时候,就跳出循环,执行后面的代码
            Console.WriteLine("while后");
        }
    }
}

 

[展开全文]