Matrix2. Даны целые положительные числа M и N. Сформировать целочисленную матрицу размера M × N, у которой все элементы J-го столбца имеют значение 5*J (J = 1, …, N).
>Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | program Matrix2; var a:array [1..10,1..10] of integer; M, N, i, j:Integer; begin Write('M: '); Readln(M); Write('N: '); Readln(N); for i:=1 to M do for j:=1 to N do a[i,j]:=5*j; for i:=1 to M do begin for j:=1 to N do Write(' : ',a[i,j]); writeln(' : '); end; end. |
Решение C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # include <iostream> # include <windows.h> # include <cmath> # include <iomanip> # include <fstream> # include "IOMatrix.h" using namespace std; int main () { SetConsoleCP(1251); SetConsoleOutputCP(1251); int M,N; cout << "Введите положительные числа M и N: "; cin >> M >> N; int a[M][N]; for (int row = 0; row < M; ++row) { for (int col = 1; col <= N; ++col) { a[row][col] = 5*col; } } for (int row = 0; row < M; ++row) { for (int col = 1; col <= N; ++col) { cout << a[row][col] << " "; } cout << endl; } system ("pause"); return 0; } |
tak navernoe?
int m = int.Parse(Console.ReadLine());
int n = int.Parse(Console.ReadLine());
int[,] array = new int[m, n];
for (int i = 0; i < array.GetLength(0); i++)
{
for (int j = 0; j < array.GetLength(1); j++)
{
array[i, j] = int.Parse(Console.ReadLine());
}
}
for (int i = 0; i < array.GetLength(0); i++)
{
for (int j = 0; j < array.GetLength(1); j++)
{
array[0, j] = 5 * array[0, j];
Console.Write(array[i, j] + " ");
}
Console.WriteLine();
}
Решения на java:
import java.util.Scanner;
public class matrix2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(«Row : «);
int m = scan.nextInt();
System.out.println(«Column : «);
int n = scan.nextInt();
int[][] a = new int[m][n];
for (int i = 0; i < m; ++i){
for (int j = 0; j < n; ++j){
a[i][j] = 5 * (j + 1);
}
}
for (int i = 0; i < m; ++i){
for (int j = 0; j < n; ++j){
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}