По разделам

 

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


Дана матрица размера M ×N и целое число K (1≤K ≤M). Найти сумму и произведение элементов 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 < n; ++i){
        s += a[k - 1][i];
        p *= a[k - 1][i];
    }
    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,M)
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)

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

Код (Pascal)

program Matrix17;
var
  a:array [1..10,1..10] of integer;
  Sum, Mult,M, N, K, 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 j:=1 to N do
    begin
     Sum:=Sum+a[K,j];
     Mult:=Mult*a[K,j];
 
    end;
 
   Write('Sum:',Sum, ' Mult: ',Mult);
end.
									




Matrix. Абрамян
Matrix 1 Просмотров: 11744
Matrix 2 Просмотров: 4306
Matrix 3 Просмотров: 4439
Matrix 4 Просмотров: 3316
Matrix 5 Просмотров: 4963
Matrix 6 Просмотров: 3294
Matrix 7 Просмотров: 4054
Matrix 8 Просмотров: 3087
Matrix 9 Просмотров: 3967
Matrix 10 Просмотров: 2820
Matrix 11 Просмотров: 4287
Matrix 12 Просмотров: 2991
Matrix 13 Просмотров: 2935
Matrix 14 Просмотров: 1882
Matrix 15 Просмотров: 2568
Matrix 16 Просмотров: 2455
Matrix 17 Просмотров: 4290
Matrix 18 Просмотров: 2108
Matrix 19 Просмотров: 2768
Matrix 20 Просмотров: 3184
Matrix 21 Просмотров: 3205
Matrix 22 Просмотров: 1942
Matrix 23 Просмотров: 4416
Matrix 24 Просмотров: 2168
Matrix 25 Просмотров: 2342
Matrix 26 Просмотров: 2017
Matrix 27 Просмотров: 1977
Matrix 28 Просмотров: 1878
Matrix 29 Просмотров: 1789
Matrix 30 Просмотров: 1736
Matrix 31 Просмотров: 1469
Matrix 32 Просмотров: 1336
Matrix 33 Просмотров: 1432
Matrix 34 Просмотров: 1767
Matrix 35 Просмотров: 1490
Matrix 36 Просмотров: 1570
Matrix 37 Просмотров: 1304
Matrix 38 Просмотров: 1401
Matrix 39 Просмотров: 1327
Matrix 40 Просмотров: 1348
Matrix 41 Просмотров: 1096
Matrix 42 Просмотров: 1442
Matrix 43 Просмотров: 1112
Matrix 44 Просмотров: 1116
Matrix 45 Просмотров: 1153
Matrix 46 Просмотров: 1213
Matrix 47 Просмотров: 1378
Matrix 48 Просмотров: 1170
Matrix 49 Просмотров: 1191
Matrix 50 Просмотров: 1510
Matrix 51 Просмотров: 1350
Matrix 52 Просмотров: 1337
Matrix 53 Просмотров: 1194
Matrix 54 Просмотров: 983
Matrix 55 Просмотров: 1046
Matrix 56 Просмотров: 842
Matrix 57 Просмотров: 1027
Matrix 58 Просмотров: 1275
Matrix 59 Просмотров: 1048
Matrix 60 Просмотров: 970
Matrix 61 Просмотров: 1004
Matrix 62 Просмотров: 987
Matrix 63 Просмотров: 1136
Matrix 64 Просмотров: 1137
Matrix 65 Просмотров: 1011
Matrix 66 Просмотров: 853
Matrix 67 Просмотров: 885
Matrix 68 Просмотров: 990
Matrix 69 Просмотров: 869
Matrix 70 Просмотров: 986
Matrix 71 Просмотров: 822
Matrix 72 Просмотров: 861
Matrix 73 Просмотров: 937
Matrix 74 Просмотров: 889
Matrix 75 Просмотров: 785
Matrix 76 Просмотров: 909
Matrix 77 Просмотров: 928
Matrix 78 Просмотров: 866
Matrix 79 Просмотров: 917
Matrix 80 Просмотров: 2494
Matrix 81 Просмотров: 1260
Matrix 82 Просмотров: 968
Matrix 83 Просмотров: 1359
Matrix 84 Просмотров: 865
Matrix 85 Просмотров: 940
Matrix 86 Просмотров: 872
Matrix 87 Просмотров: 960
Matrix 88 Просмотров: 775
Matrix 89 Просмотров: 785
Matrix 90 Просмотров: 942
Matrix 91 Просмотров: 811
Matrix 92 Просмотров: 770
Matrix 93 Просмотров: 795
Matrix 94 Просмотров: 941
Matrix 95 Просмотров: 776
Matrix 96 Просмотров: 877
Matrix 97 Просмотров: 892
Matrix 98 Просмотров: 1035
Matrix 99 Просмотров: 1008
Matrix 100 Просмотров: 1124

Комментарии

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

  1. Avatar
    Electro Full
    2020-07-22
    #include <bits/stdc++.h> using namespace std; typedef int i; int main() { srand(time(0)); system("chcp 1251"); i m , n , k; cin >> m >> n >> k; vector < vector < i > > ar(m , vector < i > (n)); for (size_t i = 0;i < ar.size();++i) for (size_t j = 0;j < ar.at(i).size();++j) ar.at(i).at(j) = rand() % 90 + 10; for (auto i : ar) { for (auto j : i) cout << j << " "; cout << endl; } cout << endl; i sum = 0 , prod = 1; for (size_t i = 0;i < n;++i) { sum += ar[k - 1][i]; prod *= ar[k - 1][i]; } cout << sum << " " << prod << endl; return 0; }


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