16 votes 16 votes Consider the following function definition. void greet(int n) { if(n>0) { printf("hello"); greet(n-1); } printf("world"); } If you run $\textsf{greet(n)}$ for some non-negative integer $\textsf{n},$ what would it print? $\textsf{n}$ times "hello", followed by $\textsf{n+1}$ times "world" $\textsf{n}$ times "hello", followed by $\textsf{n}$ times "world" $\textsf{n}$ times "helloworld" $\textsf{n+1}$ times "helloworld" $\textsf{n}$ times "helloworld", followed by "world" Programming in C tifr2018 programming programming-in-c recursion + – Arjun asked Dec 10, 2017 edited Nov 20, 2022 by Lakshman Bhaiya Arjun 2.8k views answer comment Share Follow See all 9 Comments See all 9 9 Comments reply Show 6 previous comments gauravkc commented Jan 24, 2018 reply Follow Share When n=0, printf Hello will not execute. But printf world will 1 votes 1 votes Devshree Dubey commented Jan 24, 2018 reply Follow Share Okay. Thank you so much!!! 0 votes 0 votes Rohit Gupta 8 commented Jan 24, 2018 reply Follow Share Here it is. https://gateoverflow.in/179276/tifr2018-a-7 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Jusk take n as 0 World is getting printed only now take n=1 Hello World followed by world by Iteration, you can see when you take n=k k times (hello world) followed by one single world which was the base condition Hence Option A shashankrustagi answered Dec 23, 2020 shashankrustagi comment Share Follow See all 0 reply Please log in or register to add a comment.