mbah_bejo

biggestnumber(recursive)

Dec 8th, 2020
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int terbesar(int a[], int n){
  6.     if (n==1)
  7.     return a[n];
  8.     else{
  9.     return max(terbesar(a,n-1),a[n]);
  10. }
  11. }
  12.  
  13. int main(){
  14.     int a[] = {1, 10, 8, 2, 7, 1};
  15.     int n = sizeof(a) / sizeof(a[0]);
  16.     cout<< "bilangan terbesar adalah "<< terbesar(a, n);
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment