Question

(Find the smallest element) use pointers to write a function that finds the smallest element in...

(Find the smallest element) use pointers to write a function that finds the smallest element in an array of integers. Use {1,2,4,5,10,100,2,-22} to test the function. using the following header.

int minindex(double* list, int size)

example output:

array size: 8

number 1: 1

number 2: 2

number 3: 4

number 4: 5

number 5: 10

number 6: 100

number 7: 2

number 8: -22

smallest element is: -22

C++ only.

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

#include<iostream>
using namespace std;
int minindex(double* , int );
int main()
{
int num,i;
cout<<"array size: ";
cin>>num;
double a[num];
for(i=0;i<num;i++)
{
cout<<"number "<<i+1<<":";
cin>>a[i];
}
int min = minindex(a,num);
cout<<"smallest element is: "<<min;
return 0;
}
int minindex(double *list,int size)
{
int i=0,min;
min=*(list+i);
for(i=0;i<size;i++)
{
if(min>*(list+i))
min=*(list+i);
}
return min;
}

Add a comment
Know the answer?
Add Answer to:
(Find the smallest element) use pointers to write a function that finds the smallest element in...
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
  • average Function Write a function that finds an average of the array using only pointers (and...

    average Function Write a function that finds an average of the array using only pointers (and pointer arithmetic) to move through the array. Test the function in a driver program. Function header: double average(int* array, int size)

  • Using PYTHON: (Find the index of the smallest element) Write a function that returns the index...

    Using PYTHON: (Find the index of the smallest element) Write a function that returns the index of the smallest element in a list of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header: def indexOfSmallestElement(lst): Write a test program that prompts the user to enter a list of numbers, invokes this function to return the index of the smallest element, and displays the index. PLEASE USE LISTS!

  • Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...

    Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence 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. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...

  • Write a c program that finds the uncommon elements from two array elements using pointers only...

    Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • Create a function l_mode that finds the index of the value that occurs most often in...

    Create a function l_mode that finds the index of the value that occurs most often in an array. The input to your function is an array of integers A and the number of elements in the array 0 < n <= 10^3. Assuming v is the most frequent element in the array, your function will return the index i of the first (leftmost) occurrence of v in A. You can assume that -500 <= A[i] <= 500, for 0 <=...

  • Write a program in C++ language that finds the largest number in an array of positive...

    Write a program in C++ language that finds the largest number in an array of positive numbers using recursion. Your program should have a function called array_max that should pass in an int array, and an int for the size of the array, respectively, and should return an int value. As an example, given an array of size 10 with contents: {10, 9, 6, 1, 2, 4, 16, 8, 7, 5} The output should be: The largest number in the...

  • Write in C++ program Larger than n In a program, write a function that accepts three...

    Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers.                                           The number n to test the file numbers. Output to the console: The...

  • Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the...

    Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the size of an array. Then create an integer array of that exact size. Ask the user to enter a maximum value and then write a loop to fill the array with random numbers with value in the range of 1 to the maximum value. For example, if the maximum value is 100, random numbers must have value 1 to 100 inclusive. Input size of...

  • Write a function that returns the index of the smallest element in an array of integers....

    Write a function that returns the index of the smallest element in an array of integers. If there are more such elements than one, return the smallest index. C programming

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