Question: Write a C++ program to find the largest and smallest element of an array. You will need to input the array as an input. It

Write a C++ program to find the largest and smallest element of an array. You will need to input the array as an input. It shouldn't be any limitation on the number of array elements. Array items can be any number from negative to positive.

this is what i have so far and i cant figure what i am doing wrong...please help

//int num[10];

double largestNum = 0;

double smallestNum = 0;

int size;

cout << " enter number elements: " << endl;

cin >> size;

double number[size];

int index;

for (index = 0; index < size; index++)

cout << " enter the numbers: " << index << endl;

cin >> number[index];

//double largestNum = num[0];

//double smallestNum = num[0];

for (index = 1; index < size; index++)

if (num[largestNum] < num[index])

largestNum = index;

cout << "largest element is: " << num[largestNum] << endl;

//for (int index = 1; index < 10; index++)

if (num[smallestNum] > num[index])

smallestNum = index;

cout << "smallest element is: " << num[smallestNum] << endl;

}

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!