Sum replacement

struct node *add()
{
struct node *ptr;
if(ptr!=NULL){
s=s+ptr->item;
ptr->left=add();
ptr->right=add();
}
printf("%\nd",s);
return ptr;
}

void sumlevel(struct node *ptr,int k){
if(k==1)
{
s=0;
ptr=add();
}
sumlevel(ptr->left,k-1);
//ptr=ptr->right;
sumlevel(ptr->right,k-1);
}

int main()
{
int n,k=1;
int ch,d1,d2;
struct node *ptr;
ptr=build();
printf("\nBINARY TREE\n");
display(ptr);
ch=height(ptr);
printf("\nHeight is %d\n",ch);
while(k<=ch)
{printlevel(ptr,k);
printf("\n");
k++;
}
count(ptr);
d1=height(ptr->left);
d2=height(ptr->right);
printf("\ndiameter of tree is %d",d1+d2);
k=1;
while(k<=ch){
sumlevel(ptr,k);
k++;
}
display(ptr);
return 0;
}
I have declared ‘s’ as global can you please tell me the error

Thanks for clearing my previous doubts on time :slight_smile:

@Saurabh10
hello saurabh,
pls save ur code at https://ide.codingblocks.com/ and share the generated link here.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.