Untitled
unknown
c_cpp
3 years ago
1.2 kB
8
Indexable
/* ============================================================================ Name : ex_yana_2d_arr_all.c Author : Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <stdlib.h> #include <time.h> int main( void ) { srand( time( NULL ) ); const int rows = 4, cols = 5; int arr[ rows ][ cols ]; int i, j; for ( i = 0; i < rows; ++i ) { for ( j = 0; j < cols; ++j ) { arr[ i ][ j ] = rand() % 21 - 10; printf( "%4d", arr[ i ][ j ] ); } puts( "" ); } // В указанной пользователем строке найти максимальный элемент int n; do { printf( "Введите номер строки :) : " ); scanf( "%d", &n ); if ( n < 1 || n > 4 ) puts( "Неверно введён номер строки :( " ); else break; } while ( 1 ); int max = arr[ n - 1 ][ 0 ]; for ( j = 1; j < cols; ++j ) { if ( arr[ n - 1 ][ j ] > max ) max = arr[ n - 1 ][ j ]; } printf( "Максимальный элемент в строке номер %d = %d", n, max ); return EXIT_SUCCESS; }
Editor is loading...