Want more features on Pastebin? Sign Up, it's FREE!

max

By: nguyenvanquan7826 on Feb 25th, 2014  |  syntax: C++  |  size: 0.43 KB  |  views: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data