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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you name some types of inheritance?

639


Can a destructor be called directly?

599


What is the renewal class?

2161


What are main features of oop?

629


What is destructor example?

593






Advantage and disadvantage of routing in telecom sector

783


What do you mean by overloading?

576


What is ambiguity in inheritance?

623


design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)

6143


How to hide the base class functionality in Inheritance?

636


What is the purpose of polymorphism?

675


What is the significance of classes in oop?

587


What is encapsulation process?

575


What is polymorphism what are the different types of polymorphism?

561


What is super in oop?

593