Where now stands that small knot of villages known as the
Endians, a mighty forest once stood. Indeed, legand has it
that you could have stoodon the edge of the wood and seen
it stretch out for miles, were it not for the trees getting
in the way.
In one section of the forest, the trees stood in a row and
were of hight from 1 to n, each hight occurring once and
once only.
A tree was only visible if there were no higher trees
before it in the row.
For example, if the heights were 324165, the only visible
trees would have been those of height 3,4 & 6.

Write a Program that takes an array of integers
representing the heights of the trees in the row as input
and prints the list of the visible trees.

Answers were Sorted based on User's Feedback



Where now stands that small knot of villages known as the Endians, a mighty forest once stood. Ind..

Answer / manoj pathak

#include<iostream.h>
#include<conio.h>

void main()
{
int n,i,tree[50],show_t;
clrscr();
cout<<"Enter the value of N: ";
cin>>n;
for(i=0;i<n;i++)
{
cin>>tree[i];
}
cout<<"Tree which will be visible : ";
show_t=tree[0];
cout<<tree[0];
for(i=1;i<n;i++)
{
if(show_t < tree[i])
{
cout<<", "<<tree[i];
show_t=tree[i];
}
}
getch();
}

Is This Answer Correct ?    22 Yes 8 No

Where now stands that small knot of villages known as the Endians, a mighty forest once stood. Ind..

Answer / harshal

ANSWER

Is This Answer Correct ?    3 Yes 7 No

Post New Answer

More C++ Code Interview Questions

write a program that calculate the volume of cylinder after user enters radius and height and show the algorithm used

1 Answers   Jomo Kenyatta University,


i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

0 Answers  


Create a program to read two random data set in two files named data1.txt and data2.txt manifold contains integer numbers, whereas data2.txt file contains the float type numbers. Simpanlahmasing each into 2 pieces of data that is an array of type integer array and an array of type float, then calculate the average numbers in the second array.

0 Answers  


Min-Max Write an algorithm that finds both the smallest and largest numbers in a list of n numbers and calculate its complexity T(n).

1 Answers   Infosys, Qatar University,


how to find out the maximum number out of the three inputs.

6 Answers   ABC, Apple, C3I, HP, TCS,






Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

5 Answers   ADP, Amazon, HCL, IBM, Infosys, Satyam, TCS, Vimukti Technologies,


can we declare an object of a class in another class?(assume both class as public classes)

1 Answers   Microsoft,


Implement a command console for changing settings on a particular object. The command console should allow you to enter a string and will return the response (very similar to a terminal session). The commands are as follows: SET propertyname=newvalue will change the target object’s member named “propertyname” to have a value equal to “newvalue”. If the input value is incompatible (i.e. an int being set to a string), print out an appropriate error message. GET propertyname will print out the current value of the target object’s member named “propertyname”. GET * will print out a list of all target object members and their current values. The system should be extensible for future commands and should accept an arbitrary object, such that another developer could insert another object into the system and rely on the command console to get and set the properties correctly.

0 Answers   ABC, Guidance Software,


how to write a program that opens a file and display in reverse order?

0 Answers   SMC,


solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)

0 Answers  


How do I store linked list datas into an array?

1 Answers  


1. Write a program using one dimensional array that calculates the sum and average of the five input values from the keyboard and prints the calculated sum and average.

2 Answers  


Categories