Question

Create a function mult_arr which accepts two pointers-to-double as input along with an integer reflecting the...

Create a function mult_arr which accepts two pointers-to-double as input along with an integer reflecting the length of each array. The function should return void. Using pointer arithmetic to access the array elements, compute the element-wise product of the two arrays in-place (the result is stored in the first array). The function should return void. In main, read in two arrays of 10 values from the user following the I/O format seen in the example run below. On a new line, print the output following the format shown below. Save your code as prob2.c.

Example Run

> 1 1 1 1 1 1 1 1 1 1

> 2 2 2 2 2 2 2 2 2

2 2 2 2 2 2 2 2 2 2 2 2

Homework Answers

Answer #1

Code:

#include <stdio.h>
void mult_arr(int *a,int *b,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        *(a+i)=*(a+i)**(b+i);
    }
}
int main()
{
    int i,a[10],b[10];
    printf("Read arry A:");
    for(i=0;i<10;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("Read arry B:");
    for(i=0;i<10;i++)
    {
        scanf("%d",&b[i]);
    }
    mult_arr(a,b,10);
    printf("Multiplication array:");
    for(i=0;i<10;i++)
    {
        printf("%d ",a[i]);
    }
    return 0;
}

Screenshots:

Know the answer?
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
Similar Questions
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
In this lab, we want to get some practice with pointers -- specifically, the basic syntax...
In this lab, we want to get some practice with pointers -- specifically, the basic syntax of declaring them, storing memory addresses into them, dereferencing them, and seeing how they work with pointer arithmetic in the context of built-in, C-style arrays. Unless specified otherwise, you can use any valid variable names you wish. The requirements for this program are as follows: Part A Declare a pointer-to-int, initialized to nullptr. Declare an int variable, initialized to some value of your choice....
C++ Create a program that will use pointers to determine the average (to 1 decimal place)...
C++ Create a program that will use pointers to determine the average (to 1 decimal place) of a series of grades entered into an array. You can assume a maximum of 15 students and the user will end input with a sentinel value. Make sure to use pointer increment and a pointer comparison while loop, and not array notation or array index numbers or offsets. You will use a function called getgrades. Send the array name (a pointer constant) to...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return the number of positive and negative in the array through the use of parameters. In addition, it also returns the number of 0s in the array as the return value. For example, array of {10, 20, -30, -40, 50, 0, 60} will return 4 for positives, 2 for negatives and 1 for 0's as the return value. 2. Write a function named "rotateRight" that...
Write a function that accepts an int array arr, the array’s size sz and integer n,...
Write a function that accepts an int array arr, the array’s size sz and integer n, the function should create a new array that it’s n times the array arr. The fucntion copy the content of arr to the new array n times. The Example arr = {5, 2, 1} n=3 Newarr = {5, 2, 1, 5, 2, 1, 5, 2, 1} (c++)
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
Write a C++ function which accepts two array of integers (like arr1 and arr2) of the...
Write a C++ function which accepts two array of integers (like arr1 and arr2) of the same size (100), then create a new array (like arr3) with the same size (100) and assign the sum of corresponding elements in arr1 and arr2 to the new array (arr3) and return back arr3 from the function. You don't need to write the main function. For example sum of corresponding elements in arr1 and arr2 to be assigned to arr3 should be like:...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
The local taqueria has decided they need to raise their prices. In order to soften the...
The local taqueria has decided they need to raise their prices. In order to soften the blow to their customers, they also want to rename all their burritos to make them sound more desirable. Your C++ program should create two arrays in main() - one string array with 3 burrito types and one float array with 3 associated prices, defined below: string names[] = {"Carnitas", "Pollo", "Veggie"}; float prices[] = {6.95, 6.25, 5.95}; Now, main should declare a string pointer...
In C programming language write a function that takes two arrays as input m and n...
In C programming language write a function that takes two arrays as input m and n as well as their sizes: size_m and size_n, respectively. Then it checks for each element in m, whether it exists in n. The function should update a third array c such that for each element in m: the corresponding position/index in c should be either 1, if this element exists in m, or 0, if the element does not exist in n
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT