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

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 Task17 {
 
public class Task17 {
  
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 36: Line 31:
 
a[i][j] = (int) (100 * Math.random());
 
a[i][j] = (int) (100 * Math.random());
 
System.out.printf("%3d", a[i][j]);
 
System.out.printf("%3d", a[i][j]);
if (max < a[i][j]) max = a[i][j];
+
if (max < a[i][j]) {
 +
                    max = a[i][j];
 +
                }
 
    }
 
    }
  
Line 56: Line 53:
  
 
<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], k = 100, max;
 +
   
 +
    for (int j = 0; j < m; j++) {
 +
       
 +
        max = 0;
 +
       
 +
        for (int i = 0; i < n; i++) {
 +
            a[i][j] = rand() % 100;
 +
            printf("%3d", a[i][j]);
 +
            if (max < a[i][j]) {
 +
                max = a[i][j];
 +
            }
 +
        }
 +
       
 +
        if (k > max) {
 +
            k = max;
 +
        }
 +
       
 +
        cout << "  Max = " << max << "\n";
 +
    }
 +
   
 +
    cout << "-------------------------------------\n";
 +
    cout << " Искомое число: " << k << "\n\n";
 +
 +
    return 0;
 +
}
 
</pre>
 
</pre>
  

Latest revision as of 07:43, 21 April 2015

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


Contents

[edit] Java

public class Task17 {

    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 k = 100, max;

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

	    max = 0;

	    for (int i = 0; i < n; i++) {
		a[i][j] = (int) (100 * Math.random());
		System.out.printf("%3d", a[i][j]);
		if (max < a[i][j]) {
                    max = a[i][j];
                }
	    }

	    if (k > max) {
		k = max;
	    }

	    System.out.println("   Max = " + max);
	}

        System.out.println("-------------------------------------");
	System.out.println(" Искомое число: " + k);
    }
}


[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], k = 100, max;
    
    for (int j = 0; j < m; j++) {
        
        max = 0;
        
        for (int i = 0; i < n; i++) {
            a[i][j] = rand() % 100;
            printf("%3d", a[i][j]);
            if (max < a[i][j]) {
                max = a[i][j];
            }
        }
        
        if (k > max) {
            k = max;
        }
        
        cout << "   Max = " << max << "\n";
    }
    
    cout << "-------------------------------------\n";
    cout << " Искомое число: " << k << "\n\n";

    return 0;
}


[edit] Pascal




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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools