# Programmers puzzle

1,310.6K Views

What will be the output of the program-
print(5);

```
void print (int n){

if (n>0){

printf(“hello”);

print(n-1);

}

printf(“world”);

}

```

SherlockHolmes Expert Asked on 18th May 2016 in

For print(5)
Output-
hellohellohellohellohelloworldworldworldworldworldworld

Suppose n=3
The output shall be
hellohellohelloworldworldworldworld

Basically, the number of hello’s shall be equal to value of n and the number of world’s following it shall be n+1.

psn Guru Answered on 19th May 2016.

print(5) will print hellohellohellohellohelloworldworldworldworldworldwolrd.
basically print(n) will print hello…..(n times)world(n+1 times)

dyj Expert Answered on 19th May 2016.

Hi,

The code prints Hello for N times as if(n>0) is TRUE

and it prints World also for N times as if(n>0) is TRUE  1 more World for if(n>0)  FALSE case.

Horteppa Starter Answered on 6th June 2016.

• ## More puzzles to try-

• ### Chelsea Player Statement

Eight Chelsea player makes the following statements : 1. Seven of us are lying here. 2. Six of us are ...Read More »
• ### Confused sisters riddle

Three sisters are identical triplets. The oldest by minutes is Aliza, and Aliza always tells anyone the truth. The next ...Read More »
• ### Find the Unique Number

Can you find the least possible number such that If the number is divided by 3, it gives the remainder ...Read More »
• ### Life in a forest riddle

A forest exists somewhere on Earth. This forest has no life except for trees. After a storm, a tree was ...Read More »
• ### Man on Mountain

There is a man, stood on top of a mountain, frozen holding a peice of straw. How did he get ...Read More »
• ### Cleaver Calculation Riddle

Five teams were competing in cricket where they faced each other exactly once. After the tournament, the following is the ...Read More »
• ### He was not wet

John was drowned by he was not wet. How?Read More »
• ### How long will it take the patient to consume all the five tablets?

A patient was diagnose with some ailment. He was given five different tablets to take at night at an interval ...Read More »
• ### Complete The Series

N  U  S  J  M  E  V  ?Read More »
• ### Smart land division puzzle!!

An old man is dying and doesn’t have enough time. The problem bugging him is the division of his land. ...Read More »
• ### Cut not to eat

What is cut on a table, but is never eaten?Read More »
• ### Enters it blind and leaves it seeing

There is a house. One enters it blind and leaves it seeing. What is it?Read More »
• ### Black & Brown Stuff riddle

Filling these items with black/brown stuff I am sure you will be agreeing Ensures everyone in the office Starts the ...Read More »
• ### Solve the murder mystery

A couple went to river rafting on a hill station. Two days after their departure, the husband returned alone. He ...Read More »
• ### Soft and Cuddly

I am soft and cuddly that soothe your heart. But, If you pick my last name I am going to ...Read More »
• ### Trick Gift Brain Teaser

Cindy opened twenty five presents. Duke opened five presents. John opened fifteen presents. Judging by the statements, can you decipher ...Read More »