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

Write pseudo code for push in a stack?

2 Answers   emc2,


What is the use of unnamed namespaces in OOPS? The only advantage I know is that they dont need the scope resolution operator while accessing them. I want to know some other advantages of unnamed namespaces...

2 Answers  


Why is polymorphism important in oop?

0 Answers  


Which is better struts or spring?

0 Answers  


Can java compiler skips any statement during compilation time?

0 Answers  






What is balance factor?

0 Answers  


What is pure oop?

0 Answers  


if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?

1 Answers  


What is an object?

14 Answers   HCL,


all about pointers

2 Answers  


There are 2 empty jars of 5 and 3 liters capacity. And a river is flowing besides. I want to measure 4 liters of wanter using these 2 jars. How do you do this?

2 Answers  


what is the use of mutable key word

3 Answers   HCL,


Categories