PuzzlersWorld.com

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

Output of the recursive program

(9 votes, average: 2.89 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

  • Objective Questions set C/C++ – Part 6
  • Objective Questions set C/C++ – Part 5
  • Find Number present only once
  • Find the Min solution: Facebook hacker Cup 2013 Qual Round
  • implement isPalindrome(int n)
  • 3 SUM problem
  • RoboElection solution: Facebook hacker cup 2013 Round 2
  • Find a pythagorean triplet from an array
  • Basic Concepts C/C++
  • Output of the recursive program

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 © 2023 · 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