Advertisement
_takumi

ok

Sep 12th, 2022
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. // Нахождение наибольшего элемента в целочисленном массиве
  4. int Max(int *array, int len, int max) {
  5.     if (!array || (len <=0) ) {
  6.         return -1;
  7.     }
  8.     max = array[0];
  9.     for (int i=1; i <= len; i++) {
  10.         if (max < array[i]) {
  11.             max = array[i];
  12.         }
  13.     }
  14.     return 0;
  15. }
  16.  
  17. //---------------------------------------------------------
  18. int main(int argc, char *argv[]) {
  19.     int arr[5] = { 17, 21, 44, 2, 60 };
  20.     int max = arr[0];
  21.  
  22.     if ( Max(arr, 5, max) != 0 ) {
  23.         printf("strange error\n");
  24.         return 1;
  25.     }
  26.     printf("max value in the array is %d\n", max);
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement