Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp21
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {    
  9.             double[] va = new double[] { 1, 2, 3, 11 };
  10.             double[] vb = new double[] { 4, 5, 6, 22 };
  11.             double[] vc = Add(va, vb);
  12.  
  13.             Print(va);
  14.             Print(vb);
  15.             Print(vc);
  16.         }
  17.         private static double[] Add(double[] vectorA, double[] vectorB)
  18.         {
  19.             if (vectorA.Length != vectorB.Length)
  20.             {
  21.                 return null;
  22.             }
  23.  
  24.             double[] vectorC = new double[vectorA.Length];
  25.  
  26.             for (int i = 0; i < vectorC.Length; i++)
  27.             {
  28.                 vectorC[i] = vectorA[i] + vectorB[i];
  29.             }
  30.  
  31.             return vectorC;
  32.         }
  33.  
  34.         private static void Print(double[] vector)
  35.         {
  36.             Console.Write("{ ");
  37.  
  38.             foreach (double d in vector)
  39.             {
  40.                 Console.Write(d + " ");
  41.             }
  42.  
  43.             Console.WriteLine("}");
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement