По разделам

 

Решение задачи Matrix 18


Дана матрица размера M ×N и целое число K (1 ≤ K ≤ N). Найти сумму и произведение элементов K-го столбца данной матрицы.

Код (C/C++)

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int m, n, k, s = 0, p = 1;
    cin >> m >> n>> k;
    int a[m][n];
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < n; ++j)
            cin >> a[i][j];
    }
    for(int i = 0; i < m; ++i){
        s += a[i][k - 1];
        p *= a[i][k - 1];
    }
    cout << s << " " << p;
    return 0;
}

Код (Python)

import random
import numpy as np

M = random.randrange(2,7)
N = random.randrange(2,7)
K = random.randrange(0,N)
print("M = ",M,"; N = ",N,"; K = ",K)
a = np.zeros((M, N))

for i in range(M):
    for j in range(N):
        a[i][j] = random.randrange(1,5)
print(a)

b = a[:,K:K+1]
print(b)
Sum = sum(b)
Product = np.product(b)
print("Sum: ",Sum)
print("Product: ",Product)
									

Код (Pascal)

program Matrix18;
var
  a:array [1..10,1..10] of integer;
  M, N, K, Sum, Mult, i, j:Integer;
 
begin
 Write('N: ');
 Readln(N);
 Write('M: ');
 Readln(M);
 Write('K: ');
 Readln(K);
 
 for  i:=1 to M do
  begin
   writeln(i,': ');
   for j:=1 to N do
    begin
     Write(j,' : ');
     Read(a[i,j]);
    end;
  end;
 
  Sum:=0;
  Mult:=1;
 
  for i:=1 to M do
   begin
    Sum:=Sum+a[i,K];
    Mult:=Mult*a[i,K];
   end;
 
   Write('Sum:',Sum, ' Mult: ',Mult);
end.
									




Matrix. Абрамян
Matrix 1 Просмотров: 11666
Matrix 2 Просмотров: 4271
Matrix 3 Просмотров: 4393
Matrix 4 Просмотров: 3275
Matrix 5 Просмотров: 4937
Matrix 6 Просмотров: 3241
Matrix 7 Просмотров: 4024
Matrix 8 Просмотров: 3045
Matrix 9 Просмотров: 3934
Matrix 10 Просмотров: 2778
Matrix 11 Просмотров: 4260
Matrix 12 Просмотров: 2956
Matrix 13 Просмотров: 2902
Matrix 14 Просмотров: 1851
Matrix 15 Просмотров: 2530
Matrix 16 Просмотров: 2433
Matrix 17 Просмотров: 4244
Matrix 18 Просмотров: 2081
Matrix 19 Просмотров: 2738
Matrix 20 Просмотров: 3146
Matrix 21 Просмотров: 3170
Matrix 22 Просмотров: 1910
Matrix 23 Просмотров: 4384
Matrix 24 Просмотров: 2144
Matrix 25 Просмотров: 2308
Matrix 26 Просмотров: 1982
Matrix 27 Просмотров: 1943
Matrix 28 Просмотров: 1851
Matrix 29 Просмотров: 1756
Matrix 30 Просмотров: 1702
Matrix 31 Просмотров: 1438
Matrix 32 Просмотров: 1312
Matrix 33 Просмотров: 1407
Matrix 34 Просмотров: 1742
Matrix 35 Просмотров: 1460
Matrix 36 Просмотров: 1547
Matrix 37 Просмотров: 1281
Matrix 38 Просмотров: 1367
Matrix 39 Просмотров: 1298
Matrix 40 Просмотров: 1315
Matrix 41 Просмотров: 1073
Matrix 42 Просмотров: 1399
Matrix 43 Просмотров: 1086
Matrix 44 Просмотров: 1086
Matrix 45 Просмотров: 1120
Matrix 46 Просмотров: 1181
Matrix 47 Просмотров: 1350
Matrix 48 Просмотров: 1132
Matrix 49 Просмотров: 1161
Matrix 50 Просмотров: 1483
Matrix 51 Просмотров: 1323
Matrix 52 Просмотров: 1309
Matrix 53 Просмотров: 1161
Matrix 54 Просмотров: 961
Matrix 55 Просмотров: 1025
Matrix 56 Просмотров: 814
Matrix 57 Просмотров: 988
Matrix 58 Просмотров: 1251
Matrix 59 Просмотров: 1007
Matrix 60 Просмотров: 947
Matrix 61 Просмотров: 975
Matrix 62 Просмотров: 961
Matrix 63 Просмотров: 1109
Matrix 64 Просмотров: 1101
Matrix 65 Просмотров: 988
Matrix 66 Просмотров: 833
Matrix 67 Просмотров: 851
Matrix 68 Просмотров: 961
Matrix 69 Просмотров: 836
Matrix 70 Просмотров: 954
Matrix 71 Просмотров: 793
Matrix 72 Просмотров: 832
Matrix 73 Просмотров: 906
Matrix 74 Просмотров: 867
Matrix 75 Просмотров: 757
Matrix 76 Просмотров: 879
Matrix 77 Просмотров: 905
Matrix 78 Просмотров: 840
Matrix 79 Просмотров: 889
Matrix 80 Просмотров: 2457
Matrix 81 Просмотров: 1220
Matrix 82 Просмотров: 933
Matrix 83 Просмотров: 1330
Matrix 84 Просмотров: 839
Matrix 85 Просмотров: 906
Matrix 86 Просмотров: 843
Matrix 87 Просмотров: 935
Matrix 88 Просмотров: 753
Matrix 89 Просмотров: 758
Matrix 90 Просмотров: 909
Matrix 91 Просмотров: 778
Matrix 92 Просмотров: 735
Matrix 93 Просмотров: 767
Matrix 94 Просмотров: 910
Matrix 95 Просмотров: 752
Matrix 96 Просмотров: 853
Matrix 97 Просмотров: 870
Matrix 98 Просмотров: 1011
Matrix 99 Просмотров: 984
Matrix 100 Просмотров: 1097

Комментарии

Чтобы написать комментарии вам нужно войти в систему или зарегистрироваться



Заявка на расчет