GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
164 views

Avoid the any syntax error ,if there is:What will be the output of the following code ?
 

#inlcude<stdio.h>
void myfun(int i)
{   
    if(i>0) {
        myfun(i-1);
        printf("%d",i);
        myfun(i-1);
    }
}
int main() {
    myfun(3);
}

asked in Programming by (107 points) 1 3 5
edited by | 164 views
1213121

1 Answer

+4 votes

execute the tree from DFS manner you will get the output 1213121

answered by Boss (7.9k points) 6 41 119

Why isn't the right sub tree getting executed first? What I mean is shouldn't the solution be 1211213 ?

PLease explain a bit more. 

The traversal must always be from left to right.

So it will execute the left subtree first - printing : 121

then the root : printing : 3

and then the right subtree, printing : 121


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Top Users Oct 2017
  1. Arjun

    23338 Points

  2. Bikram

    17048 Points

  3. Habibkhan

    7912 Points

  4. srestha

    6228 Points

  5. Debashish Deka

    5438 Points

  6. jothee

    4968 Points

  7. Sachin Mittal 1

    4772 Points

  8. joshi_nitish

    4286 Points

  9. sushmita

    3964 Points

  10. Rishi yadav

    3794 Points


Recent Badges

Popular Question makhdoom ghaya
Popular Question junaid ahmad
Notable Question learner_geek
Notable Question jothee
Popular Question jothee
Notable Question Jeffrey Jose
Notable Question air1ankit
Nice Question jothee
Verified Human shaleen25
Popular Question jothee
27,290 questions
35,142 answers
83,920 comments
33,231 users