Практикум по программированию. Основы. Массивы. Максимальный элемент матрицы

From AsIsWiki
(Difference between revisions)
Jump to: navigation, search
 
Line 9: Line 9:
  
 
<pre>
 
<pre>
import java.util.Scanner;
 
import java.lang.Math;
 
 
 
public class Task09 {
 
public class Task09 {
  
Line 18: Line 15:
  
 
     public static void main(String[] args) {
 
     public static void main(String[] args) {
       
 
        Scanner in = new Scanner(System.in);
 
 
          
 
          
 
System.out.println();
 
System.out.println();
Line 54: Line 49:
  
 
<pre>
 
<pre>
 +
// g++ 4.2
 +
 +
#include <iostream>
 +
 +
using namespace std;
 +
 +
int main() {
 +
 +
    cout << "\n Поиск максимального элемента матрицы\n";
 +
    cout << "--------------------------------------\n";
 +
    cout << " Матрица:\n";
 +
 
 +
    srand((int)time(0));
 +
   
 +
    const int n = 3;
 +
    const int m = 3;
 +
   
 +
    int a[n][m], max = 0;
 +
   
 +
    for (int i = 0; i < n; i++) {
 +
        for (int j = 0; j < m; j++) {
 +
           
 +
            a[i][j] = rand() % 100;
 +
           
 +
            if (max < a[i][j]) {
 +
                max = a[i][j];
 +
            }
 +
           
 +
            printf("%3d", a[i][j]);
 +
        }
 +
       
 +
        cout << "\n";
 +
    }
 +
   
 +
    cout << "---------------------------------\n";
 +
    printf(" Максимальный элемент: %d\n\n", max);
 +
 +
    return 0;
 +
}
 
</pre>
 
</pre>
  

Latest revision as of 13:09, 19 April 2015

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


Contents

[edit] Java

public class Task09 {

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

    public static void main(String[] args) {
        
	System.out.println();
        System.out.println(" Поиск максимального элемента матрицы ");
        System.out.println("--------------------------------------");
        System.out.println(" Матрица:");

	int a[][] = new int[n][m];
	int max = 0;

	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < m; j++) {

		a[i][j] = (int) (100 * Math.random());

		if (max < a[i][j]) {
		    max = a[i][j];
		}

		System.out.printf("%3d", a[i][j]);
	    }

            System.out.println();
	}

        System.out.println("---------------------------------");
	System.out.printf(" Максимальный элемент: %d\n", max);
    }
}


[edit] C++

// g++ 4.2

#include <iostream>

using namespace std;

int main() {

    cout << "\n Поиск максимального элемента матрицы\n";
    cout << "--------------------------------------\n";
    cout << " Матрица:\n";
  
    srand((int)time(0));
    
    const int n = 3;
    const int m = 3;
    
    int a[n][m], max = 0;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            
            a[i][j] = rand() % 100;
            
            if (max < a[i][j]) {
                max = a[i][j];
            }
            
            printf("%3d", a[i][j]);
        }
        
        cout << "\n";
    }
    
    cout << "---------------------------------\n";
    printf(" Максимальный элемент: %d\n\n", max);

    return 0;
}


[edit] Pascal




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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools