C#加减乘运算

using System;

namespace 加减乘除
{

 class Class1
 {
  private static int [,]add(int [,]array1,int [,]array2)
  {
   int [,]array = new int[3,3];
   
   for (int i = 0; i < 3; i++)
   {
    for (int j = 0; j < 3; j++)
    {
     array[i,j] = array1 [i,j] + array2[i,j];
    }
   } 

            return array;
  }
  private static int [,]sub(int [,]array1,int [,]array2)
  {
   int [,]array = new int[3,3];
   
   for (int i = 0; i < 3; i++)
   {
    for (int j = 0; j < 3; j++)
    {
     array[i,j] = array1 [i,j] - array2[i,j];
    }
   } 
   return array;
  }
  
  private static int [,]mup(int [,]array1,int [,]array2)
  {
   int [,]array = new int[3,3];

   for (int i = 0; i < 3; i++)
   {
    int j;
    for ( j = 0; j < 3; j++)
    {
     array[i,j] = 0;
     for (int k = 0; k < 3; k++)
     array[i,j] += array1[i,k]*array2[k,j];
    } 
   }
   
     return array;
  }
  private static int [,]Input(int [,] array1)
  {
              int [,]array = new int[3,3];
               
   for (int i = 0; i < 3; i++)
   {
    for (int j = 0; j < 3; j++)
    {
     array[i,j] = Convert.ToInt32(Console.ReadLine());
    }
   } 
  return array; 
  }
  private static void Output(int [,]array1)
  {
   for (int i = 0; i < 3; i++)
   {
    int j;
    for ( j = 0; j < 3; j++)
    {
     Console.Write("{0,4}",array1[i,j]);
    }
       Console.WriteLine();
   }

  }
  
  
  public static void Main(string[] args)
  {
   
    int [,]a = new int[3,3];
    int [,]b = new int[3,3];
             int [,]c = new int[3,3];
             int [,]d = new int[3,3];
             int [,]e = new int[3,3];
   
   Console.WriteLine("请输入第一个距阵:");
     a = Input(a);
    
    
   Console.WriteLine("请输入第2个距阵:");
     b = Input(b);
    
   Console.WriteLine("第一个数组为");
             Output(a);
   Console.WriteLine("第2个数组为");
    Output(b);
   Console.WriteLine("进行加法运算:");
   c = add(a,b);
     Output(c);
   Console.WriteLine("进行减法运算:"); 
   d = sub(a,b);
     Output(d);
   Console.WriteLine("进行乘法运算:");
   e = mup(a,b);
     Output(e);
   
     Console.ReadLine();
  }
 }
}
程序还有很多需要改进的地方 比如想计算任意2个数组的加减乘  等等  读者想做加减乘中的一项 等

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值