2020-09-30

1 篇文章 0 订阅
1 篇文章 0 订阅

学习记录 

10.输出一年每个月份的天数

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

namespace ConsoleApplication21
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] month = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            for (int i = 0; i < 12; i++)
            { Console.WriteLine("{0}月有D{1}天", i + 1, month[i]); }
            Console.Read();

        }
    }
}

11.输出100个1-99之间的随机整数(练习Random函数的使用)

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

namespace ConsoleApplication21
{
    class Program
    {
        static void Main(string[] args)
        {
            
            int[] nums = new int[100];
            
            Random n = new Random();
            for (int i = 0; i < 100; i++)
            {
                nums[i] = n.Next(99);
                Console.WriteLine("第{0}个1-99之间的随机整数{1}",i+1, nums[i]);
            }
            Console.Read();
            

        }
    }
}

 12.输入一个数,判断其是否出现在程序11所产生的随机整数中(程序12建立在11的基础上)

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

namespace ConsoleApplication21
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(" 输入一个数:");
            int s = Convert.ToInt32(Console.ReadLine());
            int[] nums = new int[100];
            Random n = new Random(); int i = 0;
            for (; i < 99; i++)
            {
                nums[i] = n.Next(99);
                
            }
            if (s == nums[i])
                    Console.WriteLine(i);
                else
                    Console.WriteLine(-1);
            Console.Read();
            

        }
    }
}

13.判断生成的100个随机数之中的最大值和最小值(程序11的引申程序)

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

namespace ConsoleApplication21
{
    class Program
    {
        static void Main(string[] args)
        {
            
            int[] nums = new int[100];
            int max,min;
             max=min=nums[0];
            Random n = new Random();
            for (int i = 0; i < 100; i++)
            {
                nums[i] = n.Next(99);
                if (nums[i] > max) max = nums[i];
                if (nums[i] < min) min = nums[i];
            }
            Console.WriteLine("该数组最大值是{0},最小值是{1}", max, min);
            Console.Read();
            

        }
    }
}

15.求两个二维数组之和

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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;
            int[,] a = new int[5, 6] { { 1, 2, 3, 4, 5, 6 }, {  4, 5, 6,1, 2, 3 }, { 1, 4, 5, 6,2, 3 }, {  3, 4,1, 2, 5, 6 }, { 1, 4, 5, 2, 3, 6 } };
            int[,] b = new int[5, 6] { { 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1 } };
            int[,] c = new int[5, 6];
            for (i = 0; i < c.GetLength(0); i++)
                for (j = 0; j < c.GetLength(1); j++)              
                            c[i, j] = a[i, j] + b[i, j];
            for(i=0;i<5;++i)
            {
                for (j = 0; j < 6; ++j)
                    Console.Write("{0,3:d}", c[i, j]);
                Console.WriteLine();
            }
            Console.Read();

        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值