Language: C

int d(int x){
  int d=0,p;
  p=u[x].parent;
 
  while(p!=-1){
    p=u[p].parent;
    d++;
  }
 
  return d;
}
int h(int x) {
  int i,a=0,y;
  
  for(i=0;i<n;i++) {
    if(u[i].parent==x) {
      y=h(i)+1;
      if(y>a) a=y;
    }
  }
  return a;
}

int main(){
  int i,id,r,l;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    u[i].parent=-1;
    u[i].right=-1;
    u[i].left=-1;
    u[i].degree=0;
  }
 
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&l,&r);
    u[id].left=l;
    u[u[id].left].right=r;
    if(u[id].left!=-1){
      u[u[id].left].parent=id;
      u[id].degree++;
    }
    if(u[u[id].left].right!=-1){
      u[u[u[id].left].right].parent=id;
      u[id].degree++;
    }
  }
 
  for(i=0;i<n;i++){
    if(u[i].parent==-1)
      printf("node %d: parent = -1, sibling = -1, degree = %d, depth = 0, height = %d, root\n",i,u[i].degree,h(i));
 
    else if(u[i].degree==0)
      printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, leaf\n",i,u[i].parent,s(i),u[i].degree,d(i),h(i));
 
    else printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, internal node\n",i,u[i].parent,s(i),u[i].degree,d(i),h(i));
  }
 
  return 0;
}
 

Compiler output:
main.c: In function 'd':
main.c:3:5: error: 'u' undeclared (first use in this function)
    3 |   p=u[x].parent;
      |     ^
main.c:3:5: note: each undeclared identifier is reported only once for each function it appears in
main.c: In function 'h':
main.c:15:13: error: 'n' undeclared (first use in this function)
   15 |   for(i=0;i<n;i++) {
      |             ^
main.c:16:8: error: 'u' undeclared (first use in this function)
   16 |     if(u[i].parent==x) {
      |        ^
main.c: In function 'main':
main.c:27:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   27 |   scanf("%d",&n);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | int d(int x){
main.c:27:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   27 |   scanf("%d",&n);
      |   ^~~~~
main.c:27:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:27:15: error: 'n' undeclared (first use in this function)
   27 |   scanf("%d",&n);
      |               ^
main.c:30:5: error: 'u' undeclared (first use in this function)
   30 |     u[i].parent=-1;
      |     ^
main.c:52:7: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   52 |       printf("node %d: parent = -1, sibling = -1, degree = %d, depth = 0, height = %d, root\n",i,u[i].degree,h(i));
      |       ^~~~~~
main.c:52:7: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:52:7: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:52:7: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:55:7: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   55 |       printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, leaf\n",i,u[i].parent,s(i),u[i].degree,d(i),h(i));
      |       ^~~~~~
main.c:55:7: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:55:111: error: implicit declaration of function 's' [-Wimplicit-function-declaration]
   55 |       printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, leaf\n",i,u[i].parent,s(i),u[i].degree,d(i),h(i));
      |                                                                                                               ^
main.c:57:10: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   57 |     else printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, internal node\n",i,u[i].parent,s(i),u[i].degree,d(i),h(i));
      |          ^~~~~~
main.c:57:10: note: include '<stdio.h>' or provide a declaration of 'printf'