fork(1) download
  1. #include <stdio.h>
  2.  
  3. int heap[101];
  4.  
  5. int find_pow(int a, int b){
  6. if(b == 0) return 1;
  7. int ans = 0, curr = 1, j;
  8. for(j=0; j<b; j++){
  9. ans += curr;
  10. curr *= a;
  11. }
  12. return ans;
  13. }
  14.  
  15. int find_height(int n){
  16. int ans = 0, curr_ele = 0;
  17. while(curr_ele < n){
  18. curr_ele += find_pow(2, ans);
  19. ans++;
  20. }
  21. return ans;
  22. }
  23.  
  24. int main(){
  25. int n, j;
  26. printf("enter the number of elements in the heap : ");
  27. scanf("%d",&n);
  28. printf("now enter the elements : ");
  29. for(j=0; j<n; j++)
  30. scanf("%d",&heap[j]);
  31. printf("the height of the heap is : %d\n",find_height(n));
  32. return 0;
  33. }
Success #stdin #stdout 0s 10320KB
stdin
10
1 236 32 6 2 1 236 32 6 2
stdout
enter the number of elements in the heap : now enter the elements : the height of the heap is : 4