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

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  


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 enter 10 number of integer entries into an array n and then odds up all the odd entries. the program then displays the result. plssss answer assss fast asss u can...

1 Answers  


Code for Two Classes for Doing Gzip in Memory?

0 Answers  


what is the best algorithm to sort out unique words from a list of more than 10 million words(1 crore+)? we need the best technique in the terms of execution time.

9 Answers   TCS,






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  


i don't know about working of nested for loop can any one help me

0 Answers  


what is virtual constroctor ? give an exam for it?-(parimal dhimmar)

2 Answers  


write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used

0 Answers   Jomo Kenyatta University,


Coin Problem You are given 9 gold coins that look identical. One is counterfeit and weighs a bit greater than the others, but the difference is very small that only a balance scale can tell it from the real one. You have a balance scale that costs 25 USD per weighing. Give an algorithm that finds the counterfeit coin with as little weighting as possible. Of primary importance is that your algorithm is correct; of secondary importance is that your algorithm truly uses the minimum number of weightings possible. HINT: THE BEST ALGORITHM USES ONLY 2 WEIGHINGS!!!

1 Answers   Motorola, Qatar University,


Complexity T(n) What is the time complexity T(n) of the following portions of code? For simplicity, you may assume that n is a power of 2. That is, n = 2k for some positive integer k. a) ? for (i = 1; i <= n; i++) { j = n; cout << i << ? ? j << ? ? << endl; } b) ? for (i = 0; i <= n; i += 2) { j = n; cout << i << ? ? j << ? ? << endl; } c) ? for (i = n; i >= 1; i = i/2) { j = n; cout << i << ? ? j << ? ? << endl; } d) for (i = 1; i <= n; i++) { j = n; while (j >= 0) { cout << i << ? ? j << ? ? << endl; j = j - 2; } }

0 Answers   Qatar University,


Seat Reservation prog for the theatre. Write a function for seat allocation for the movie tickets. Total no of seats available are 200. 20 in each row. Each row is referred by the Character, "A" for the first row and 'J' for the last. And each seat in a row is represented by the no. 1-20. So seat in diffrent rows would be represented as A1,A2....;B1,B2.....;........J1,J2... Each cell in the table represent either 0 or 1. 0 rep would seat is available , 1 would represent seat is reserved. Booking should start from the last row (J) to the first row(A). At the max 20 seats can be booked at a time. if seats are available, then print all the seat nos like "B2" i.e (2 row, 3 col) otherwise Print "Seats are not available." and we must book consecutive seats only.

1 Answers   Nagarro,


Categories