- How to compare 2 adjacent elements and, if they are unequal, get out of the cycle?
- How to determine the row number of a two-dimensional array, the sum of the elements of which is maximum? How is this better done?
-
#include "stdafx.h" #include "stdio.h" #include "conio.h" #include <locale.h> #define HB 5 void main() { setlocale(LC_CTYPE, "Russian"); // вывод на русском языке int a[HB]; // массив int k; // индекс int ok; // 1 - последовательность неубывающая printf("Проверка, упорядочен ли массивn"); printf("по возрастаниюn"); printf("Введите массив (%i целых чисел ", HB); printf("в одной строке) и нажмите <Enter>n"); for (k = 0; k < HB; k++) scanf("%i", &a[k]); k = 0; ok = 1; do { if (a[k] > a[k + 1]) ok = 0; k++; } while (k < HB - 1 && ok); printf("Элементы массива "); if (!ok) printf("не "); printf("упорядочены по возрастаниюn"); printf("nДля завершения работы нажмите <Enter>"); _getch(); }