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

Assume in University Every student in university as entity, prepare a class for student that store the roll no, name, dob of student, and make funtion of deletion, manipulation, addition of student record.

0 Answers  


What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }

0 Answers  


Complexity T(n) Write a linear-time algorithm that sorts n distinct integers, each of which is between 1 and 500. Hint: Use a 500-element array. (Linear-time means your algorithm runs in time c*n + b, where c and b are any constants that do not depend on n. For example, your algorithm can run in time n, or time 2n + 1, or time 5n + 10, or time 100n + 6, but not time c*n*n = c*n?.)

1 Answers   Qatar University,


write a program that can locate elements in array.

1 Answers  


How reader and writer problem was implemented and come up with effective solution for reader and writer problem in case we have n readers and 1 writer.

6 Answers   Microsoft, NetApp,






Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

0 Answers   iGate,


write a program to calculate the radius for a quadratic equation use modular programming(function abitraction)hint use quadratic function

1 Answers   ICAN, Jomo Kenyatta University,


write a program to convert temperature from fa height into celcius and vise versa,use modular programming

0 Answers   Jomo Kenyatta University,


using friend function find the maximum number from given two numbers from two different classes.write all necessary functions and constructor for the classes.

1 Answers   TCS,


what is the diffrence between ++x , x++ pleaaaaase ???

7 Answers  


using repetition structure. Write a c program that will accept five numbers. The program should count and output the total count of even numbers and total count of add numbers.

2 Answers  


write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n

0 Answers   Jomo Kenyatta University,


Categories