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.
Answer Posted / 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 |
Post New Answer View All Answers
write a program that can LOCATE and INSERT elements in array using c++ programming languages.
A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect
write a program that reads a series of strings and prints only those strings begging with letter "b"
write a program that reverses the input number of n.Formulate an equation to come up with the answer.
1+1/2!+1/3!+...+1/n!
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.
Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file
Write a (n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)
Performance Algorithm A performs 10n2 basic operations and algorithm B performs 300 lg n basic operations. For what value of n does algorithm B start to show its better performance?
Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.
Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?
Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37
find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L