PuzzlersWorld.com

  • Hacker Puzzle
  • Interview Puzzles
  • Number Puzzles
  • Maths Puzzles

Output of the recursive program

(10 votes, average: 2.70 out of 5)

May 6, 2014 by puzzler 1 Comment

what will be the output of this program

void print (int n)
{
	if (n>0)
	{
		printf(“hello”);
		print(n-1);
	}
	printf(“world”);
}
Click here to See AnswersHide Answer
It will print, N times “hello” and then by N+1 times “world”.
First it will call print function recursively N times and will print world after it comes out of the if block. “world” is printed N+1 times since when n ==0, it will not go inside if block and will print world and return.
  • Share on Whatsapp
  • Share on Facebook
  • Share on Twitter
Facebook Comments
Next Puzzle
Average speed of train

Checkout more Interview Questions Tags: Recursion Questions, Snapdeal Interview Questions, Solved Puzzles

Comments

  1. Pushker says

    January 8, 2015 at 11:32 pm

    Its will print n times hello then n+1 times world because one failure.

    Reply

Leave a Comment Cancel reply

Submit your Puzzle

You may also like

  • Swap two integer variables
  • implement isPalindrome(int n)
  • Security problem solution: Facebook hacker cup 2013 Round 1
  • Lawnmower Solution: Google codejam 2013 Qual Round
  • Full Binary Tree Solution – Google Code Jam
  • Manage Your Energey Solution: Google codejam 2013 Round 1A
  • Reverse a link list without using another
  • Objective Questions set C/C++ – Part 4
  • RoboElection solution: Facebook hacker cup 2013 Round 2
  • Permutations solution: Facebook hacker cup 2013 Round 2

Categories

  • Aive hi Puzzles
  • Akbar and Birbal
  • Alphabetical Puzzles
  • Bollywood Puzzles
  • Google Code jam
  • Hindi Riddles
  • Interview Puzzles
  • Interview Questions
  • Logical Puzzles
  • Malayalam Puzzles
  • Maths Puzzles
  • Miscellaneous
  • Number Puzzles
  • Picture Puzzles
  • Riddles
  • Tamil Puzzles
  • Technical

Social

  • View puzzlersworld’s profile on Twitter
privacy policy

Copyright © 2025 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in

  • Hacker Puzzle
  • Logo Puzzles
  • Optical Illusions
  • WhatsApp Puzzles
  • Picture Puzzles
  • Riddles
    ▼
    • Hindi Riddles
  • Bollywood Puzzles
  • Alphabetical Puzzles
  • Aive hi Puzzles
  • Interview Puzzles
  • Logical Puzzles
  • Interview Questions
    ▲
    • Data Structures
    • Binary Tree
    • Algorithms
    • Recursion Questions
    • Amazon Interview Questions
    • Snapdeal Interview Questions
    • Google Code jam
  • Technical
  • Akbar and Birbal
  • Number Puzzles
  • Maths Puzzles
  • Miscellaneous