write a function that takes an integer array as an input and
finds the largest number in the array. You can not sort
array or use any API or searching needs?

Answers were Sorted based on User's Feedback



write a function that takes an integer array as an input and finds the largest number in the array...

Answer / pawan

#include<iostream>
using namespace std;

int main()
{
int name[5],big,i;

for(i=0; i<=4; i++) {
cout << "Enter a value" << i << ":";
cin >> name[i];
}
cout << "name contains:";
for(i=0; i<=4; i++) {
cout << name[i]<< "\n";
}

big = name[0];
for(i = 0; i <= 4; i++) {
if(name[i] > big)
big = name[i];
}

cout << "The Bigest Number::" << big << endl;

return 0;
}

Is This Answer Correct ?    39 Yes 0 No

write a function that takes an integer array as an input and finds the largest number in the array...

Answer / pawan

By using dynamic memory allocation..............

#include<iostream>
#include<new>
using namespace std;

int main()
{
int big,i,*p,sz;

cout << "Enter the size of an array u wanted:";
cin >> sz;

try {
p = new int(sz);
}catch(bad_alloc xa) {
cout << "allocation failure";
return 1;
}
for(i=0; i<sz; i++) {
cout << "Enter a value" << i << ":";
cin >> p[i];
}
cout << "name contains:";
for(i=0; i<sz; i++) {
cout << p[i]<< "\n";
}

big = p[0];
for(i = 0; i < sz; i++) {
if(p[i] > big)
big = p[i];
}

cout << "The Bigest Number::" << big << endl;

return 0;
}

Is This Answer Correct ?    6 Yes 1 No

Post New Answer

More OOPS Interview Questions

ambiguity regulation of multiple inheritance with example.

1 Answers  


Write a program to get the binary tree.

3 Answers   ABC,


We have a scale and 7 balls. 1 ball is heavier than all the rest. How to determine the heaviest ball with only 3 possible weighing attempts?

8 Answers   IBM, Sage, Vertex,


program for insertion ,deletion,sorting in double link list

0 Answers  


explain defference between structure and class with example

1 Answers  






what is the difference between function template and template of function?explain with example.

2 Answers  


Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation

0 Answers   TCS,


What are the 4 pillars of oop?

0 Answers  


There are 2 empty jars of 5 and 3 liters capacity. And a river is flowing besides. I want to measure 4 liters of wanter using these 2 jars. How do you do this?

4 Answers  


what is multi level inheritance give n example ?

13 Answers   HDFC, Hulas Steel, Ness Technologies,


In multilevel inheritance constructors will be executed from the .... class to ... class

2 Answers   ABCO, TCS,


//what is wrong with the programme?? #include<iostream.h> template <class first> class dd { first i; public: void set(); void print(); }; void dd< first>:: set() { cin>>i; } void dd< first>::print() { cout<<"\n"<<i; } void main() { dd <char>g; g.set(); g.print(); }

1 Answers  


Categories