码迷,mamicode.com
首页 > Web开发 > 详细

.net 新手上路,已疯->_<-

时间:2017-10-09 19:47:57      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:处理   2-2   一个   ble   信息   最大值   else   电脑   简单   

今天.net 上机实验,已哭死在电脑前

把一些能简单的全都简单处理了。

 

 

 

1. 编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出。

代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

// a,b记录长方形的长和宽

//a,b,d记录三角形的三个边

//c记录周长,s记录面积,e作为判断条件当e等于三时退出程序

//q用于变量转换

//t 用于判断三角形能否构成的判断变量

namespace work1_1

{

    class Program

    {

        static void Main(string[] args)

        {

            int   e = 0;

            while(e != 3)

            {

            int a=0, b=0, c=0,s=0,d=0,q=0,t=1;

            Console.WriteLine("             三角形和长方形面积&周长");

            Console.WriteLine("             请选择");

            Console.WriteLine("             1.长方形");

            Console.WriteLine("             2.三角形");

            Console.WriteLine("             3.退出");

            string p = Console.ReadLine();

            e = Convert.ToInt32(p);

            //Console.WriteLine(e);

            if (e == 3)

                break;

            else if (e == 1)

                {

                    Console.Write("请输入矩形的长:");

                    p = Console.ReadLine();

                    a = Convert.ToInt32(p);

                  

                    Console.Write("请输入矩形的宽:");

                    p = Console.ReadLine();

                    b = Convert.ToInt32(p);

                   

                    c = 2 * (a + b);

                    s = a * b;

                    Console.WriteLine("矩形的周长为:" + c);

                    Console.WriteLine("矩形的面积为:" + s);

                }

             else if (e == 2)

             {

                while(t != 0)

                 {

                 Console.Write("请输入三角形的第一条边:");

                 p = Console.ReadLine();

                 a = Convert.ToInt32(p);

 

                 Console.Write("请输入三角形的第二条边:");

                 p = Console.ReadLine();

                 b = Convert.ToInt32(p);

 

                 Console.Write("请输入三角形的第三条边:");

                 p = Console.ReadLine();

                 d = Convert.ToInt32(p);

 

                 if (a < b)

                 {

                     q = a;

                     a = b;

                     b = q;

                 }

                 if (a < c)

                 {

                     q = a;

                     a = d;

                     d = q;

                 }

                 if (a >= b + d)

                     Console.WriteLine("输入的三角形的边不能构成三角形请重新输入!");

                 if (a < b + d)

                 {

                     c = a + b + d;

                     //秦九照公式 s=根号{c/2*(c/2-a)*(c/2-b)*(c/2-d)}

                     s =c/2*(c/2-a)*(c/2-b)*(c/2-d);

                     Console.WriteLine("三角形的周长为:" + c);

                     Console.WriteLine("三角形的面积为:" + Math.Sqrt(s));

                     t = 0;

                 }

 

                 }

                }

            }

        }

    }

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

//3-5春季,6-8夏季,9-11秋季12-2冬季

namespace work1_2

{

    class Program

    {

 static void Main(string[] args)

        {

            int b = 1;

            while (b != 0)

            {

                Console.WriteLine("请输入月份(输入数字1-12):");

                int a;

                string s = Console.ReadLine();

                a = Convert.ToInt32(s);

                if (a == 3 || a == 4 || a == 5)

                {

                    Console.WriteLine("春季")

  b = 0;

                }

                else if (a == 6 || a == 7 || a == 8)

                {

                    b = 0;

                    Console.WriteLine("夏季");

                }

                else if (a == 9 || a == 10 || a == 11)

                {

                    b = 0;

 Console.WriteLine("秋季");

                }

                else if (a == 1 || a == 2 || a == 12)

                {

                    b = 0;

                    Console.WriteLine("冬季");

                }

                else

                    Console.WriteLine("输入错误,重新输入!");

            }

 }

    }

}

 

3. 编写程序,用 while 循环语句实现下列功能:有一篮鸡蛋,不止一个,有人两个两

个数,多余一个,三个三个数,多余一个,再四个四个地数,也多余一个,请问这篮鸡蛋至

少有多少个。

代码如下:using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace work1_3

{

    class Program

    {

        static void Main(string[] args)

        {

            int s=1;

            while(s!=0){

  if (s % 2 == 1 && s % 3 == 1 && s % 4 == 1 && s!=1)

                    break;

                else

                    s++;

            }

            Console.WriteLine(s);

        }

    }

}

4. 编写程序,计算数组中奇数之和和偶数之和。

代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace work1_4

{

    class Program

    {

        static void Main(string[] args)

        {

            //eNum记录偶数之和

            //ueNum记录奇数之和

            int eNum = 0, ueNum=0;

            int[] a = new int[10];

  for (int i = 1; i < 11; i++)

                a[i-1] = i;

            for (int i = 0; i < 10; i++)

            {

                if (a[i] % 2 == 1)

                    ueNum += a[i];

                else

                    eNum += a[i];

 }

  Console.WriteLine("数组中奇数和为:"+ueNum);

            Console.WriteLine("数组中偶数和为:" + eNum);

        }

    }

}

 

实验结果如图:

5. 编写程序,找一找一个二维数组中的鞍点(即该位置上的元素值在行中最大,在该

列上最小。有可能数组没有鞍点)。要求:

? 二维数组的大小、数组元素的值在运行时输入;

? 程序有友好的提示信息。

代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace work1_5

{

    class Program

    {

        static void Main(string[] args)

        {

            //a,b记录二维数组的长度,c记录鞍点的最多数量

            //Num二维数组名

            //Max数组记录最大值得下标,Min数组记录最小值的下标

            //t 排序时的中介值

            int a, b, c;

 

            Console.WriteLine("请输入二维数组的第一个维度长度:");

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

            Console.WriteLine("请输入二维数组的第二个维度长度:");

            b = Convert.ToInt32(Console.ReadLine());

            if (a < b)

                c = a;

            else

                c = b;

 

            double[,] Num = new double[a, b];

            double[] AnNum = new double[c];

            int[] Max = new int[2];

            int[] Min = new int[2];

            int i, j, k;

            Boolean flag = false;

            double t;

           

            //赋值

            for (i = 0; i < a; i++)

                for (j = 0; j < b; j++)

                {

                    Console.WriteLine("请给数组中的Num["+i+","+j+"]赋值");

                    Num[i,j] = Convert.ToInt32(Console.ReadLine()); ;

                }

 

 

            Console.WriteLine("该数组中的鞍点为:");

 

            for (i = 0; i < a; i++)

            {

                Max [0] = i;

                Max [1] =  0;

                t = Num[i,0];

                for (j = 0; j < b - 1; j++)

                {

                    if (t < Num[i, j + 1])

                        Max[1] = j + 1;

                }

                Min[0] = 0;

                Min[1] = Max[1];

                t = Num[0,Max[1]];

                for (k = 0; k < a; k++)

                {

                    Min[1] = Max[1];

                    if (t>Num[k,Max[1]])

                            Max[0] = k;

                }

                if (Max[0] == Min[0] && Max[1] == Min[1])

                {

                    flag = true;

                    Console.WriteLine("第" + Max[0] + "行,第" + Max[1] + "列:" + Num[Max[0], Max[1]]);

                }

               

            }

            if(!flag)

                Console.WriteLine("无");

        }

    }

}

.net 新手上路,已疯->_<-

标签:处理   2-2   一个   ble   信息   最大值   else   电脑   简单   

原文地址:http://www.cnblogs.com/Seven-Die/p/7642451.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!