Related questions
Write the complete C-function void smallest(int data[], int size, int *small); finds the smallest value in d[] and return it via reference parameter. Show a call to this function in a calling function.
Below is the C program with explanation: -
Explanation: -
- Including the essential header file.
- Defining the function void smallest(int data[], int size, int *small). This function will find the smallest number in the array by using the reference variable.
- Using the for-loop to iterate over the array.
- Inside the loop, the if-statement will check whether the value stored in the array is small then the value stored in the reference variable. The loop will check for each element and update the value of the reference variable. Finally, it will store the smallest value in the reference variable.
- The function will return the null value as it is a void function.
- Defining the main function.
- Declaring the variables as per the requirement.
- Filling the array by using the for-loop.
- Storing the first value of array in the reference variable.
- Calling the function void smallest() and pass the parameters.
- Using the reference variable displaying the smallest value present in the array.
C program: -
//header file
#include <stdio.h>
//defining the void function with parameters
void smallest(int data[], int size, int *small)
{
//using the for-loop to iterate over the array
for(int i =1; i<size; i++)
{
//to check whether the value present in the array is smaller than the value
//stored in the reference variable
if(*(data + i) < *small)
{
//storing the small value into the reference variable
*small = *(data+i);
}
}
//return statement
return ;
}
//main method
int main(void)
{
//declaring the variables
int data[100], *small, size;
//prompts the user to enter the number of elements he wants to store
printf("Enter the number of elements in array\n");
//storing the number in size variable
scanf("%d", &size);
//prompts the user to enter the integers
printf("Enter %d integers\n", size);
//using a for-loop to fill the array elements
for (int i = 0; i < size; i++)
{
//filling the array
scanf("%d", &data[i]);
}
//storing the first element of array in the small variable
small = data;
*small = *data;
//calling the function and passing the parameter
smallest(data, size,small);
//print the smallest number in the array by using reference variable
printf("The smallest number in the array is: %d",*small);
}
Step by stepSolved in 3 steps with 1 images
- Question 2: multiply Problem statement In this question first we will practice function overloading and then function templates. Please follow below instructions. We can extend multiplication easily for string types if we interpret the operation as repetition. For example "code" * 3 may be interpreted as "codecodecode". In fact, languages like Python already support this operation. Write a C++ function named multiply that can multiply(repeat) an std::string by a given integer number and return the repeated string. Write another C++ function named multiply that can multiply two given integer (int type) numbers and return the product as an integer. Write another C++ function with the same name that can multiply a floating point number (double type) by a given integer number and return the product as a floating point number. We defined three functions with the same name without a problem. It is either because they have a different number of parameters, or because any of their...arrow_forwardIn C++ fill in the blanksarrow_forwardFunction Call Operator with code?arrow_forward
- C++ Write a void function that has two parameters: a value parameter called num that receives a floating point number from the calling function and a floating point reference parameter called result. The functions should do this calculation: 25.0 * num + 37 and store the answer in result. Do not do any read or write operations in the function.arrow_forwardTrue or False : The concept of function abstraction hinders our code development by confusing us with the details of the function.arrow_forwardIN C++arrow_forward
- C++ Write the defnition of the function int computeProd() with parameters that receives as arguments two integer values computes their produc and returns it to the celing function.arrow_forwardConsider the function definition: void GetNums(int howMany, float& alpha, float& beta) { int i; beta = 0; for (i = 0; i < howMany; i++) { beta = alpha + beta; } } Describe what happens in MEMORY when the GetNums function is called.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education