Практикум по программированию. Основы. Массивы. Умножение матрицы на число

From AsIsWiki
Revision as of 13:19, 9 September 2020 by Alex (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Назад · Задачи · Дальше


Contents

Java

public class Task08 {

    private static final int n = 3;
    private static final int m = 3;

    public static void main(String[] args) {
        
	System.out.println();
        System.out.println(" Умножение матрицы на -1");
        System.out.println("-------------------------");
        System.out.println(" Матрица:");

	int a[][] = new int[n][m];
	
	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < m; j++) {
		a[i][j] = (int) (5 - 10 * Math.random());
		System.out.printf("%3d", a[i][j]);
		a[i][j] *= -1;
	    }
	    System.out.println();
	}

        System.out.println("\n Результат:");

	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < m; j++) {
		System.out.printf("%3d", a[i][j]);
	    }
	    System.out.println();
	}
    }
}

C++

// g++ 4.2

#include <iostream>

using namespace std;

int main() {

    cout << "\n Умножение матрицы на -1\n";
    cout << "-------------------------\n";
    cout << " Матрица:\n";
    
    srand((int)time(0));
    
    const int n = 3;
    const int m = 3;
    
    int a[n][m];
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            a[i][j] = 5 - (rand() % 10);
            printf("%3d", a[i][j]);
            a[i][j] *= -1;
        }
        cout << "\n";
    }
    
    cout << "\n Результат:\n";
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            printf("%3d", a[i][j]);
        }
        cout << "\n";
    }

    cout << "\n";
    return 0;
}

Pascal




Назад · Задачи · Дальше

Personal tools
Namespaces

Variants
Actions
Navigation
Tools