SHARE
TWEET

max

nguyenvanquan7826 Feb 25th, 2014 45 Never
  1. /*
  2.  * Max.cpp
  3.  *
  4.  * Copyright 2014 by nguyenvanquan7826
  5.  *
  6.  * Email : nguyenvanquan7826@gmail.com
  7.  * Blog : nguyenvanquan7826.wordpress.com
  8.  *
  9.  */
  10.  
  11. #include <iostream>
  12.  
  13. using namespace std;
  14.  
  15. int max(int a[], int n){
  16.         if (n == 1) return a[n];
  17.         return max(a, n-1) > a[n-1] ? max(a, n-1) : a[n-1];
  18. }
  19.  
  20. int main (int argc, char **argv)
  21. {
  22.         int a[] = {2, 4, 6, 2, 1, 8, 12, 45, 32, 4};
  23.         cout << max(a, 10);
  24.         return 0;
  25. }
RAW Paste Data
Top