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

What is the difference between encapsulation and polymorphism?

0 Answers  


What is public, protected, private?

6 Answers   IBS, Satyam,


Program to check whether a word is in all capital letters

1 Answers  


what is polymorphism?

4 Answers  


what is opps?why it is use in programming language?

2 Answers   Wipro,






What is meant by multiple inheritance?

0 Answers  


WHAT'S THE OOPS BASIC OOPS CONCEPTS IN DOTNET

1 Answers  


define a string class. overload the operator == to compare two strings

2 Answers   Birla, Ericsson, HCL, Infosys, Infotech, MCAS, Satyam,


Get me a number puzzle game-program

0 Answers  


Which type does string inherit from?

0 Answers  


tell about copy constructor

3 Answers   Siemens,


What is the use of oops?

0 Answers  


Categories