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
What is the renewal class?
What is destructor in oop?
How do you answer polymorphism?
write a program that takes input in digits and display the result in words from 1 to 1000
What is class and example?
#include
What is polymorphism explain its types?
What is advantage of inheritance?
How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction
What does it mean when someone says I oop?
What are oops methods?
What are functions in oop?
What is abstraction example?
Which type does string inherit from?
What is the benefit of oop?