Advertisement
podsolnyxxx

Untitled

Jun 14th, 2025
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. public class Vector {
  2.  
  3.     // Скалярное произведение
  4.     static int dot(int[] a, int[] b) {
  5.         int res = 0;
  6.         for (int i = 0; i < a.length; i++) {
  7.             res += a[i] * b[i];
  8.         }
  9.         return res;
  10.     }
  11.  
  12.     // Сложение векторов
  13.     static int[] add(int[] a, int[] b) {
  14.         int[] res = new int[a.length];
  15.         for (int i = 0; i < a.length; i++) {
  16.             res[i] = a[i] + b[i];
  17.         }
  18.         return res;
  19.     }
  20.  
  21.     // Пример
  22.     public static void main(String[] args) {
  23.         int[] x = {1, 2, 3};
  24.         int[] y = {4, 5, 6};
  25.  
  26.         System.out.println("Скалярное: " + dot(x, y));
  27.  
  28.         int[] z = add(x, y);
  29.         System.out.print("Сумма: ");
  30.         for (int n : z) {
  31.             System.out.print(n + " ");
  32.         }
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement