当前位置:网站首页>2020-11-07

2020-11-07

2020-11-10 10:41:15 I'm sorry.

Application C# Language

1. seek π/2 The formula of the approximate value of :
π/2=2/12/34/3*…2n/2n-12n/2n+1, Seeking the right n=1000 when π Approximate value

using System;

namespace ConsoleApp2
{
   
   
    class Program
    {
   
   
        static void Main(string[] args)
        {
   
   
            int n;
            double pi=1;
            for (n = 1; n <= 1000; n++)
            {
   
   
                pi=pi*2*n/(2*n-1)*2*n/(2*n+1);
            }
            Console.WriteLine(" Output approximate value : " +2*pi);
        }
    }
}

 Insert picture description here
2. Design a program , Enter a decimal number , Output the corresponding hexadecimal number

using System;

namespace jinzhizhuanhuan
{
   
   
    class Program
    {
   
   
        private static string result;

        static void Main(string[] args)
        {
   
   
            
            Console.WriteLine(" Please enter decimal number : ");
            int m = int.Parse(Console.ReadLine());
            String result= Convert.ToString(m, 16);
            Console.WriteLine(" The hexadecimal number is : " );
            Console.WriteLine(m.ToString("X"));
        }
    }
}

 Insert picture description here
3. Find the array a The subscript of the maximum value in , Output subscript and maximum

using System;

namespace zuidazhix
{
   
   
    class Program
    {
   
   
        static void Main(string[] args)
        {
   
   
            int max;
            int i;
            int j;
            int[] her = new int[] {
   
    89, 23, 45, 34, 34, 56, 6, 5, 9, 21 };
            max = her[0];
            for (i = 1; i < her.Length; i++)
            {
   
   
                if (her[i] > max)
                {
   
   
                    max = her[i];
                }
            }
            Console.WriteLine(" The maximum is : " + max);
            for (j = 0; j < her.Length; j++)
            {
   
   
                if (her[j] == max) {
   
   
                    Console.WriteLine(" The subscript is : "+j);
                }
            }
        }
    }
}

 Insert picture description here

版权声明
本文为[I'm sorry.]所创,转载请带上原文链接,感谢