济南优化网站价格工作细胞第一季免费观看
11.有一个5×4的矩阵,要求编程序求出其中值最大的那个元素的值,以及其所在的行号和列号。
12.从键盘输入一行字符,统计其中有多少个单词,单词之间用空格分隔开。
13.输入一个数,判断它是奇数还是偶数,如果是奇数则进一步判断它是否为5的倍数。
14.从键盘任意输入两个数x和y,然后输入一个算术运算符(+、-、* 或 / ),并对x和y进行指定的算术运算。
15.求一元二次方程ax2+bx+c=0的根
11、首先定义一个5*4的矩阵,根据判断语句来判断,然后把行数和列数计算出来,代码如下:
 int[,] matrix =
  {
      { 1, 2, 3, 4 },
      { 5, 6, 7, 8 },
      { 9, 10, 11, 12 },
      { 13, 14, 15, 16 },
      { 17, 18, 19, 20 }
  };
     int maxValue = int.MinValue;
      int maxRow = 0;
      int maxCol = 0;
     for (int row = 0; row < matrix.GetLength(0); row++)
      {
          for (int col = 0; col < matrix.GetLength(1); col++)
          {
              if (matrix[row, col] > maxValue)
              {
                  maxValue = matrix[row, col];
                  maxRow = row;
                  maxCol = col;
              }
          }
      }
     Console.WriteLine($"最大值是: {maxValue}, 位于第 {maxRow + 1} 行,第 {maxCol + 1} 列");
  }

12、首先用分隔符来分割字符,我们可以用split方法来进行,代码如下:
 Console.WriteLine("请输入一行文本,我会统计其中的单词数量:");
  string input = Console.ReadLine();
 // 使用空格作为分隔符来分割输入的文本
  string[] words = input.Split(' ');
 // 计算单词数量
  int wordCount = words.Length;
Console.WriteLine($"单词数量:{wordCount}");

13、首先判断是否是奇数还是偶数,然后是否被5整除,用到%取余,代码如下:
Console.WriteLine("请输入一个整数:");
 int resultnumber = int.Parse(Console.ReadLine());  // 强制转换
if(resultnumber % 2 == 1)
 {
     if (resultnumber % 5 == 0)
     {
         Console.WriteLine("是奇数,并且是5的倍数");
     }
     else
     {
         Console.WriteLine("是奇数");
     }
 }
 else
 {
     Console.WriteLine("是偶数");
 }

14、需要两个数进行运算,我们要输入两次,然后进行简单的四则运算,我们可以有判断语句来进行计算,我这边用的switch,代码如下:
 Console.WriteLine("请输入数字 x:");
  double x = double.Parse(Console.ReadLine());
 Console.WriteLine("请输入数字 y:");
  double y = double.Parse(Console.ReadLine());
 Console.WriteLine("请输入算术运算符 (+, -, *, /):");
  string operatorSign = Console.ReadLine();
 double result;
  switch (operatorSign)
  {
      case "+":
          result = x + y;
          break;
      case "-":
          result = x - y;
          break;
      case "*":
          result = x * y;
          break;
      case "/":
          if (y == 0)
          {
              Console.WriteLine("除数不能为0。");
              return;
          }
          result = x / y;
          break;
      default:
          Console.WriteLine("无效的运算符。");
          return;
  }
Console.WriteLine($"结果是: {result}");

15、首先是方程中有变量,我们定义3个,然后根据判别式进行计算,代码如下:
 Console.WriteLine("请输入a, b, c的值:");
  double a = Convert.ToDouble(Console.ReadLine());
  double b = Convert.ToDouble(Console.ReadLine());
  double c = Convert.ToDouble(Console.ReadLine());
  double d = b * b - 4 * a * c; // 计算判别式
 if (d > 0) // 两个不同的实根
  {
      double x1 = (-b + Math.Sqrt(d)) / (2 * a);
      double x2 = (-b - Math.Sqrt(d)) / (2 * a);
      Console.WriteLine($"x1 = {x1}, x2 = {x2}");
  }
  else if (d == 0) // 两个相同的实根
  {
      double x = -b / (2 * a);
      Console.WriteLine($"x1 = x2 = {x}");
  }
  else // 无实数解
  {
      Console.WriteLine("无实数解");
  }

