1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Pie
3 years ago
15

Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occur

rence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value.
Computers and Technology
1 answer:
Oduvanchick [21]3 years ago
7 0

Answer:

Explanation:

The code in C++ is written as:

#include <iostream>

using namespace std;

int smallestIndex(int arr[],int size)

{

int min=arr[0],ind=0;

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

{

if(min>arr[i])

{

min=arr[i];

ind=i;              NOTE: ind serves as a variable that is holding the smallest

}                                   element index of array

 

}

return ind;

}

int main() {

int arr[15];

cout<<"Enter 15 integers: ";

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

cin>>arr[i];

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

cout<<arr[i]<<" "<<endl;

int index=smallestIndex(arr,15);

cout<<"The position of the first occurrence of the smallest element in list is: "<<index<<endl;

cout<<"The smallest element in list is: "<<arr[index];

}

OUTPUT:

Enter 15 integers:

4

5

8

4

6

1

2

1

4

5

7

9

5

7

8

4   5  8  4  6  1  2  1  4  5  7  9  5  7  8  

The position of the first occurrence for the smallest element in the list is 5

The smallest element in the list is: 1

You might be interested in
How do you create a IOS app?
Ivahew [28]
I would use x code and watch tutorials on how to code on youtube
5 0
4 years ago
What can I do with this? Lol
nikitadnepr [17]
Do with what? If you have a question please contact me ;)
3 0
3 years ago
How can you continue learning about computer science and improve your coding abilities?
Crank

Answer:

5 Ways to Improve Your Coding and Programming Skills

Take advantage of books and other free resources. ...

Sign up for a bootcamp. ...

Practice, practice, practice. ...

Engage with the computer science community. ...

Pursue a formal education in computer science.

7 0
3 years ago
Joann wants to save the building block she created for the title of her company.
konstantin123 [22]

Answer:

HTML BUILDING BLOCKS

Explanation:

4 0
3 years ago
Read 2 more answers
What size hard disc is recommended for powerpoint writting
mixas84 [53]

Answer:

Depends on how many PowerPoint files you want to store and how long they are. I'd recommend at least a 256GB hard drive to store your OS and software and then leave space for PowerPoints.

5 0
3 years ago
Other questions:
  • Game designers use background images to _______ .
    8·1 answer
  • You are going to buy a computer but first you want to do some research to help you select the best model everfi answer
    11·1 answer
  • Leslie is looking for better job opportunities in his current career path. Which career planning guideline would help him as he
    6·2 answers
  • True or false? pressing Ctrl and S is a shortcut for saving
    15·2 answers
  • ITS MAKING ME TYPE URL CODES NOW!
    6·1 answer
  • Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The user shoul
    13·1 answer
  • ____ is an approach to boundary spanning which results from using sophisticated software to search through large amounts of inte
    5·1 answer
  • ARP only permits address resolution to occur on a single network.could ARP send a request to a remote server in an IP datagram?w
    9·1 answer
  • Think of some ways you could use Excel at home. Describe one example of something in your life that could be improved or more ea
    14·1 answer
  • Need help ASAP <br><br> Thankss + BRAINLIST only for correct answers
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!