分割して治めるアルゴリズム
1008 ワード
/*
============================================================================
Name : Lesson_0705_recursion_divide.c
Author : zizhu
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// , ;
int main(void) {
puts(" :"); /* prints Hello UPC World */
int arr[20] ;
srand(time(NULL));
for(int i = 0;i<20;i++){
arr[i] = rand() % 100;//
printf("%d,", arr[i]);
}
int Max(int arr[], int count);
int max = Max(arr, 20);
printf("
:%d", max);
return EXIT_SUCCESS;
}
int Max(int arr[], int count){
if(count == 1){
return arr[0];
}else{
int max = Max(arr, count - 1);// ,
if(arr[count - 1] > max){
return arr[count - 1];
}else{
return max;
}
}
}