Question

#include <iostream>#include <string>using namespace std;// Implement printArray here// Implement deleteSmallest here//...

#include

#include

using namespace std;

// Implement printArray here

// Implement deleteSmallest here

// DO NOT CHANGE MAIN FUNCTION BELOW

int main() {

int myarray[100];

cout << "Enter number of integers : ";

int n;

cin >> n;

cout << "Enter " << n << " integers" << endl;

for (int i = 0; i < n; i++)

cin >> myarray[i];

cout << "Contents of array : ";

printArray(myarray, n);

deleteSmallest(myarray, n);

cout << "Contents of array after deleteSmallest: ";

printArray(myarray, n-1);

}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include
#include
using namespace std;
// Implement printArray here

void printArray(int arr[], int size) {
   for(int i = 0; i < size; ++i) {
       cout << arr[i] << " ";
   }
   cout << endl;
}

// Implement deleteSmallest here
void deleteSmallest(int arr[], int size) {
   int index = 0;
   for(int i = 0; i < size; ++i) {
       if(arr[i] < arr[index]) {
           index = i;
       }
   }
   for(int i = index; i < size-1; ++i) {
       arr[i] = arr[i+1];
   }
}


// DO NOT CHANGE MAIN FUNCTION BELOW
int main()
{
    int myarray[100];
    cout << "Enter number of integers : ";
    int n;
    cin >> n;
    cout << "Enter " << n << " integers" << endl;
    for (int i = 0; i < n; i++)
        cin >> myarray[i];
    cout << "Contents of array : ";
    printArray(myarray, n);
    deleteSmallest(myarray, n);
    cout << "Contents of array after deleteSmallest: ";
    printArray(myarray, n - 1);
}

Add a comment
Know the answer?
Add Answer to:
#include <iostream>#include <string>using namespace std;// Implement printArray here// Implement deleteSmallest here//...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT