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
Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.
How to improve object oriented design skills?
Plese get me a perfect C++ program for railway/airway reservation with all details.
How Do you Code Composition and Aggregation in C++ ?
class type to basic type conversion
Why polymorphism is used in oops?
What is the difference between procedural programming and oops?
Can you explain polymorphism?
Can destructor be overloaded?
What is object and class in oops?
What is multilevel inheritance explain with example?
What is data binding in oops?
What is difference between polymorphism and inheritance?
How do you define a class in oop?
What is object in oop with example?