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

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,


Given 1 to n random number, find top 10 maximum numbers and explain the time complexity of the algorithm.

1 Answers   IMO, NetApp,


Write a program using two-dimensional arrays that determines the highest and lowest of the 12 input values. Example: Enter 12 numbers: 13 15 20 13 35 40 16 18 20 18 20 14 highest: 40 lowest: 13

1 Answers  


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,


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,






create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file

0 Answers   HCL,


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  


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

0 Answers   HCL, SRCASW,


write a program in c++ to scramble a bmp image file using a scramble key 0x7c and an XOR logic. print out the original image, the scrambled image and the program. Note: the first 24bytes of a bmp file contain the header information of the file.

1 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,


How can I Draw an ellipse in 3d space and color it by using graph3d?

0 Answers  


. Remove all the blank spaces between character.Matrix is of 10* 10. eg: INPUT ------------------------------------ | N | A | | V | |T ------------------------------------- | |G | U | |P | -------------------------------------- |T | | | A | | ------------------------------------ OUTPUT: ------------------------------------ | N | A | V | T | | ------------------------------------- |G |U | P | | | -------------------------------------- |T | A | | | | ------------------------------------

2 Answers   Nagarro,


Categories