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 debug class?what is trace class? What differences are between them? With examples.

0 Answers  


Which language is not a true object oriented programming language?

0 Answers  


how to create thread in java?

17 Answers   Wipro, Infosys, IBM,


1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321

2 Answers  


when my application exe is running nad i don't want to create another exe what should i do

2 Answers   HCL,






1. Wrie a function which returns the most frequent number in a list of integers. Handle the case of more than one number which meets this criterion. public static int[] GetFrequency(int[] list)

1 Answers   Nagarro,


define oops with class and object

5 Answers   HCL, Tech Mahindra,


Write an operator overloading program to Overload ‘>’ operator so as to find greater among two instances of the class.

1 Answers  


How can we use the preprocessor #if and #elseif.

2 Answers  


difference between overloading and overridding

11 Answers  


What is multidimensional array?

1 Answers  


What is class encapsulation?

0 Answers  






Categories