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

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

价格 免费
 static void test12()
        {
            Console.WriteLine("请输入一个数组:");
            string str = Console.ReadLine();
            string[] strArray = str.Split(' ');
            int[] intArray = new int[strArray.Length];
            bool isChange = false;
            for (int i = 0; i < strArray.Length; i++)
            {
                Console.Write(strArray[i] + " ");
                int num = Convert.ToInt32(strArray[i]);
                intArray[i] = num;
            }
            for (int j = 0; j < intArray.Length-1; j++)//length-1轮比较
            {
                for (int i = 0; i < intArray.Length-1; i++)
                {
                    if (intArray[i]>intArray[i+1])
                    {
                        int temp = intArray[i];
                        intArray[i] = intArray[i + 1];
                        intArray[i + 1] = temp;
                        isChange = true;
                    }
                }
                if (isChange==false)
                {
                    break;
                }
            }
            Console.WriteLine();
            foreach (int temp in intArray)
            {
                Console.Write(temp+" ");
            }
        }

 

[展开全文]

Console.ReadLine(  )

类型一致,

Convert.ToiInt32

[展开全文]
 static void test10()
        {
            Console.WriteLine("请输入一个有序的数组:");
            string str = Console.ReadLine();
            string[] strArray = str.Split(' ');
            int[] intArray = new int[strArray.Length];
            for (int i = 0; i < strArray.Length; i++)
            {
                int num = Convert.ToInt32(strArray[i]);
                intArray[i] = num;
            }
            Console.WriteLine("请输入一个整数:");
            int n = Convert.ToInt32(Console.ReadLine());
            int m = intArray.Length-1;
            //bool find = false;//默认是未找到索引位置 m<=x<=x+1
            for (int i = 0; i < intArray.Length-1; i++)
            {                
                if (n>=intArray[i]&&n<=intArray[i+1])
                {
                    m = i;
                    //find = true;
                    break;
                }               
            }
            if (n<intArray[0])
            {
                m = -1;
            }
            int[] intArray1 = new int[intArray.Length + 1];
            for (int i = 0; i < m+1; i++)
            {
                intArray1[i] = intArray[i];
            }
            intArray1[m + 1] = n;
            for (int i = m+1; i < intArray.Length; i++)
            {
                intArray1[i+1] = intArray[i];
            }
            foreach (int temp in intArray1)
            {
                Console.Write(temp+" ");
            }

            //if (find==false)
            //{
            //    m = intArray.Length - 1;
            //}

             
        }

 

[展开全文]
static void test05()
        {
            int[] arr = new int[9] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            char[] arr1 = new char[20] { 'a','b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b' };
            float[] arr2 = new float[5] { 1.2f, 2.5f, 2.3f, 2.4f, 5.3f};
            string[] arr3 = new string[8] { "a", "b", "c", "d", "e", "f", "g", "h", };
            int[] arr4 = new int[9];
            char[] arr5 = new char[20];
            float[] arr6 = new float[5];
            string[] arr7 = new string[8];
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(arr6[i]);
            }
            for (int i = 8; i >=0; i--)
            {
                Console.WriteLine(arr[i]);
            }
            foreach (int  temp in arr1)
            {
                Console.WriteLine(temp);
            }
            Console.WriteLine(arr.Length); 
        }
        static void test06()
        {
            string name = "missuu";
            for (int i = 0; i < name.Length; i++)
            {
                Console.Write(" " + name[i]);
            }
            Console.WriteLine();
            for (int i = name.Length-1; i >=0; i--)
            {
                Console.Write(" "+name[i]);
            }
            Console.WriteLine();
            Console.WriteLine(name.ToLower());//小写
            Console.WriteLine(name.ToUpper());//大写
            name = "  missuu  ";
            Console.WriteLine(name.TrimStart() + "|");
            Console.WriteLine(name.TrimEnd() + "|");
        }

 

[展开全文]
static void test01()
        {
            for (int a = 1; a <=33; a++)
            {
                for (int b = 1; b <= 20; b++)
                {
                    for (int c = 0; c <= 50; c++)
                    {
                        if (3*a+5*b+c*2==100)
                        {
                            Console.WriteLine("a={0},b={1},c={2}",a,b,c);
                        }
                    }
                }
            }
        }

 

[展开全文]

变量:不同物品不同容器盛放

浮点数:带小数的数字(包括整数,例如1.0)

[展开全文]

结构体

struct 结构体名{

public      类型 变量名1;

⬆访问权限 类型 变量名2;

}

结构名 变量名;

变量名.变量名1=xxx;

变量名.变量名2=xxx;

 

[展开全文]
bininb · 2022-11-14 · 112-结构体 0

枚举

定义

enum aaaa 

{

   值1,值2,值3

}

 

aaaa 变量名=aaaa.值x;

[展开全文]

int name;

double jishuqi;

double pjs;

int shengao;

int zonhe;

double wendu;

[展开全文]
using System;

namespace _0026_编程题__0_3_
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            //让⽤户输⼊两个整数,然后再输⼊0-3之间的⼀个数,0代表加法,1代表减法,2代表乘法,
            //0代表加法,1代表减法,2代表乘法,3代表除法,计算这两个数字的结果.
            Console.WriteLine("输入俩个数");
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("输入0-3之间的⼀个数,0代表加法,1代表减法,2代表乘法");
            int c = Convert.ToInt32(Console.ReadLine());
            switch (c)
            {
                case 0:
                    Console.WriteLine(a + "加" + b + "等于" + (a + b));
                    break;

                case 1:
                    Console.WriteLine(a + "减" + b + "等于" + (a - b));
                    break;

                case 2:
                    Console.WriteLine(a + "乘" + b + "等于" + (a * b));
                    break;
            }
        }
    }
}

 

[展开全文]
你哈 · 2022-11-13 · 046-编程题 0

输入语句:

  • Console.ReadLine();    等待控制台输入(字符串)

输出语句:

  • Console.WriteLine();    在控制台输出

数据类型转换:

  • Convert.ToInt32();
int a = Convert.ToInt32(Console.ReadLine());

 

[展开全文]

C#取消转义字符:

  • 字符串前加@“”

字符串类型:

  • string    字符串类型

字符串取消转义后输出引号时需要用2个引号表示

 

[展开全文]

数据类型:

int           整型

double    浮点型

char         字符型

 

[展开全文]
    static void test09()
        {                    
            for (int i = 100; i < 1000; i++)
            {
                //Console.WriteLine(i);
                int a = i / 100;
                int b = (i / 10) % 10;
                int c = i % 10;               
                if (i==a*a*a+b*b*b+c*c*c)
                {                   
                    Console.WriteLine(i);                  
                }
            }            
        }
        static void test10()
        {
            Console.WriteLine("请输入一个整数n:");
            int n = Convert.ToInt32(Console.ReadLine());
            
            while (n!=0)
            {
                int a = n % 10;
                Console.WriteLine("a="+a);
                n /= 10;   
            }                          
        }
        static void test11()
        {
            Console.WriteLine("请输入一个整数n:");
            int n = Convert.ToInt32(Console.ReadLine());
            int sum = 0;
            int b = 1;
            while (n != 0)
            {
                int a = n % 10;
                if (a!=0)
                {
                    a *= b;                   
                    sum += a;
                    b *= 10;
                    Console.WriteLine(sum);
                }              
                n /= 10;
            }
            Console.WriteLine(sum);
        }

 

[展开全文]
Auuo · 2022-11-13 · 063-编程题 0

注释快捷键:

  • 添加注释:Ctrl+K Ctrl+C
  • 取消注释:Ctrl+K Ctrl+U

转义字符:

  • “\n”换行符
  • “\t” 制表符

注意:每行必须以“;”结束

[展开全文]
static void test03()
        {
            Console.WriteLine("请输入一个整数a:");
            int a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入一个正整数n:");
            int n = Convert.ToInt32(Console.ReadLine());
            int res = 1;
            for (int i = 0; i < n; i++)
            {
                res *= a;
            }
            Console.WriteLine("{0}的{1}次方是:{2}",a,n,res);
        }
        static void test04()
        {
            Console.WriteLine("请输入一个整数n:");
            int n = Convert.ToInt32(Console.ReadLine());
            int res = 1;
            for (int i = 1; i <= n; i++)
            {
                res *= i;
                Console.WriteLine("res="+res);
            }
        }
        static void test05()
        {
            Console.WriteLine("请输入一个整数n:");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入一个整数q:");
            int q = Convert.ToInt32(Console.ReadLine());
            int temp = 1;
            int res = 0;
            for (int i = 1; i <= n; i++)
            {
                temp *= q;
                res += temp;
                Console.WriteLine("temp=" + temp);
                Console.WriteLine("res=" + res);
            }
            res++;
            Console.WriteLine("res=" + res);
        }

 

[展开全文]
Auuo · 2022-11-12 · 061-编程题 0

知道执行次数   清楚首尾  for循环

终止条件充足  while

[展开全文]

授课教师

生命不息 学习不止 ~

课程特色

下载资料(1)
视频(117)
图文(3)