初学者,c#程序题代码求解!谢谢!在线等,急急急!谢谢!

2025-04-30 06:59:26
推荐回答(2个)
回答1:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace ConsoleApplication3

{

    class Program

    {

        static void Main(string[] args)

        {

            int[] arr = { 1, 2, 8, 5, 9, 6, 2, 8, 4, 2, 3, 987, 5, 2, 858, 6, 8, 4, 2, 5, 0, 2, 3, 6, 98 };

            //输入一个数,找到数组中相同的个数

            int input = Convert.ToInt32(Console.ReadLine());

            int sum = 0;


            foreach (var item in arr)

            {

                if (item == input)

                    sum++;

            }

            Console.WriteLine("一共{0}个相同", sum);


            //颠倒数组

            int[] x = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            int[] y = new int[x.Length];


            for (int i = x.Length - 1; i >= 0; i--)

            {

                y[(x.Length - 1) - i] = x[i];

            }


            foreach (var item in y)

            {

                Console.WriteLine(item);

            }


            //计算奇数

            int[] j = new int[] { 10, 22, 31, 41, 54, 67, 78, 88, 97, 66 };

            int sumjs = 0;

            for (int i = 0; i < j.Length; i++)

            {

                sumjs = i % 2 != 0 ? sumjs++ : sumjs += 0;

            }




            //数组最大值

            int[] maxs = new int[] { 10, 22, 31, 41, 54, 67, 78, 88, 97, 66 };

            int max = 0;

            for (int i = 0; i < maxs.Length; i++)

            {

                max = max > maxs[i] ? max : maxs[i];

            }


            Console.ReadKey();


        }

    }

}


回答2:

第一题
class Program
{
static void Main(string[] args)
{
int[] a = new[] { 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4 };
int b = Convert.ToInt32(Console.ReadLine());
int count = 0;
for (int i = 0; i < a.Length; i++)
{
if (b == a[i])
{
count++;
}
}
Console.WriteLine("重复的有" + count);
Console.ReadKey();

}
}
第二题
class Program
{
static void Main(string[] args)
{
int[] x = new[] { 14, 17, 2, 24, 25 };
int[] y = new int[5];
for (int i = 0; i < x.Length; i++)
{
y[i] = x[i];
Console.WriteLine("Y里面第"+(i+1)+"数组值" + y[i]);
}
Console.ReadKey();
}
}
第三题
class Program
{
static void Main(string[] args)
{
int[] x = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sum = 0;
for (int i = 0; i < x.Length; i++)
{
if (!(x[i] % 2 == 0))
{
sum += x[i];
}
}
Console.WriteLine("数组奇数总和是" + sum);
Console.ReadKey();
}
}
最后一个

class Program
{
static void Main(string[] args)
{
int[] x = new[] { 1, 22, 321, 43, 523, 63, 72, 81, 92, 110 };
x.Max();
Console.WriteLine("数组最大值是" + x.Max());
Console.ReadKey();
}
}

完毕 请采纳~ ~