Write a program that find and print how many odd numbers in
a binary tree



Write a program that find and print how many odd numbers in a binary tree..

Answer / raghuram.a

struct node
{
int data;
struct node *l;
struct node *r;
};
typedef struct node *n;
int oddnos(n root)
{
static int count;
n cur = root;
if(cur!=NULL)
{
if(cur->data%2==1)
count++;
oddnos(root->l);
oddnos(root->r);
}
return count;
}

Is This Answer Correct ?    8 Yes 5 No

Post New Answer

More C Code Interview Questions

what is variable length argument list?

2 Answers  


main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); }

1 Answers  


main() { char c; int i = 456; clrscr(); c = i; printf("%d", c); } a. 456 b. -456 c. random number d. none of the above

3 Answers   BrickRed, HCL,


main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }

1 Answers  


write a program to Insert in a sorted list

4 Answers   Microsoft,






int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().

2 Answers  


how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!

8 Answers   GATE,


main() { char *p = "hello world"; p[0] = 'H'; printf("%s", p); } a. Runtime error. b. “Hello world” c. Compile error d. “hello world”

5 Answers   HCL,


#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }

3 Answers  


why java is platform independent?

13 Answers   Wipro,


int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }

3 Answers   Cisco, HCL,


How do you write a program which produces its own source code as its output?

7 Answers  


Categories