Question

Write a function called ArrrayScalarM(...) that multiplies each element of an array by a scalar (constant...

Write a function called ArrrayScalarM(...) that multiplies each element of an array by a scalar (constant integer value). The function takes in three arguments: an integer array, the size of the array, and the scalar. Test the function, by calling it from the main program. You can initialize the array as follows:

int arrN[10] = {4, 0, 453, 1029, 44, 67, 111, 887, 4003, 1002};

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

The C code for the function and its implementation is pasted below.

/**
* C program to multiply all elements in an array with a scalar
*/

#include <stdio.h>
void ArrayScalarM(int a[],int n, int s); //function prototype

int main()
{
int i,s,n=10;
int arrN[10]={4,0,453,1029,44,67,111,887,4003,1002};

/* Input a scalar */
printf("\nEnter a scalar: ");
scanf("%d", &s);
/* Call the function to multiply elements of array with a scalar */
ArrayScalarM(arrN,n,s);
return 0;
}
void ArrayScalarM(int a[],int m,int s)
{
int i;
printf("\n Array multiplied by scalar\n");
for(i=0; i<m; i++)
{
a[i]=a[i]*s;
printf("%d\n",a[i]);
  
}
return;
}

The output screen is pasted below.

Enter a scalar: 2 Array multiplied by scalar 8 O 906 2058 88 134 222 1774 8006 2004

Add a comment
Know the answer?
Add Answer to:
Write a function called ArrrayScalarM(...) that multiplies each element of an array by a scalar (constant...
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
  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • (C++) Write a function that accepts an int array and the array’s size as arguments. The function...

    (C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...

  • Write a java Program Initialize Array. Write a Java method initArray() with the following header to...

    Write a java Program Initialize Array. Write a Java method initArray() with the following header to initialize a one-dimensional array a such that the element values (integers) are twice the index value. For example, if i = 23, then a23 = 46. The function is void with one parameter -- the integer array of a[]. Then write a main() with an int[] array2i size 100 to call

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

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

    Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and returns the index of the "last occurrence" of the largest element in the array. Include another function to print the array. Also, write a program to test your function. [HINTS) Create an array of size 15 in the main function and initialize it with the values shown in the below sample output. Pass the array and its size to function lastLargestindex; function lastLargestindex returns...

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

  • Create a hash table class/struct.in C++ Define an array that holds 27 elements. Define a function...

    Create a hash table class/struct.in C++ Define an array that holds 27 elements. Define a function called Hash(int) -This function returns the modulo of that int by the size of the table (array). Define an add function that takes an integer. -This function takes the integer, determines the hash of that number by calling the above hash function, then adds it to the table using linear probing for collision resolution. Define a function that looks up a value, it takes...

  • 1. The following program calls the function countLarger that accepts three arguments: an integer array, an...

    1. The following program calls the function countLarger that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n. The function countLarger should return the number of integers in the array that are greater than the value of the argument n. Update the program to include the definition of the function countLarger. #include <iostream> using namespace std; int countLarger(int[], int, int); // Function prototype int main() const int...

  • C++. Write a program that copies the contents of one array into another array but in...

    C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.           - in main()                    - define 2 arrays of type int, 10 elements each                              - initialize one array with numbers 1 through 10                              - initialize all elements of the second array to 0                    - call function reverseCopy with both arrays as arguments                    - display the values of array number 2 (reversed order)           - reverseCopy...

  • Java Write a function/method called CheckHash: takes two arguments, an array and an integer count n....

    Java Write a function/method called CheckHash: takes two arguments, an array and an integer count n. The function computes the exclusive OR of the hashcodes (https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#hashCode--) of the first n strings in the array (result type int).

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