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

Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?

4225


What is class and object with example?

577


Write a c++ program to display pass and fail for three student using static member function

2798


Can we define a class within the interface?

543


What is class and object in oops?

600






What are the 3 pillars of oop?

605


What does <> mean pseudocode?

610


What is static in oop?

579


How can you overcome the diamond problem in inheritance?

756


What is class encapsulation?

580


Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

1132


What is the difference between abstraction and polymorphism?

600


Explain the advantages of inheritance.

660


What is overloading and its types?

600


Is data hiding and abstraction same?

559