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
SashulF [63]
2 years ago
7

Write a C function named apply_all that expects two arrays of integers and their sizes and dynamically allocates a new array of

integers whose size is the product of the 2 array sizes. The function should loop through the second array and multiplies each element across each element of array 1 and store the product in the newly created array. The function should return a pointer to the newly allocated array.
Computers and Technology
1 answer:
andrew-mc [135]2 years ago
5 0

Answer:

The function C is as follows:

int *apply_all(int arr1[], int arr2[], int size) {

  int result[size];

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

      result[i] = arr1[i] * arr2[i];

      printf(" %d", result[i]);

  }

  return result;

}

Explanation:

This line defines the function

int *apply_all(int arr1[], int arr2[], int size) {

This declares an array that holds the result of the function

  int result[size];

This iterates through the array

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

This multiplies the corresponding elements of both arrays

      result[i] = arr1[i] * arr2[i];

This prints the result of the multiplication

      printf(" %d", result[i]);

  }

This return the a pointer to the new array

  return result;

}

<em>See attachment for complete program that includes the main</em>

Download cpp
You might be interested in
Does technology make us more alone?
Anika [276]
Both yeah and no, depending on personal opinion
3 0
3 years ago
One of the greatest benefits of dual enrollment courses is that students can receive:
Vika [28.1K]
I think the answer to this is A
7 0
2 years ago
Read 2 more answers
Half of the integers stored in the array data are positive, and half are negative. Determine the
jonny [76]

Answer:

Check the explanation

Explanation:

Below is the approx assembly code for above `for loop` :-

1). mov ecx, 0

2). loop_start :

3).    cmp ecx, ARRAY_LENGTH

4).    jge loop_end

5).    mv temp_a, array[ecx]

6).    cmp temp_a, 0

7).    branch on nge

8).        mv array[ecx], temp_a*2

9).   add ecx, 1

10).   jmp loop_start

11). loop_end :

Assumptions :-

*ARRAY_LENGTH is register with value 1000000

*temp_a is a register

Frequency of statements :-

1) will be executed one time

3) will be executed 1000000 times

4) will be executed 1000000 times

5) will be executed 1000000 times

6) will be executed 1000000 times

7) `nge` will be executed 1000000 times, branch will be executed 500000 times

8) will be executed 500000 times

9) will be executed 1000000 times

10) will be executed 1000000 times

Cost of statements :-

1) 10 ns

3) 10ns + 10ns + 10ns [for two register accesses and one cmp]

4) 10ns [for jge ]

5) 10ns + 100ns + 10ns [10ns for register access `ecx`, 100ns for memory access `array[ecx]`, 10ns for mv]

6) 10ns + 10ns [10ns for register_access `temp_a`, 10ns for mv]

7) 10ns for nge, 10ns for branch

8) 30ns + 110ns + 10ns

10ns + 10ns + 10ns for temp_a*2 [10ns for moving 2 into a register, 10ns for multiplication],

110ns for array[ecx],

10ns for mv

9) 10ns for add, 10ns for `ecx` register access

10) 10ns for jmp

Total time taken = sum of (frequency x cost) of all the statements

1) 10*1

3) 30 * 1000000

4) 10 * 1000000

5) 120 * 1000000

6) 20 * 1000000

7) (10 * 500000) + (10 * 1000000)

8) 150 * 500000

9) 20 * 1000000

10) 10 * 1000000

Sum up all the above costs, you will get the answer.

It will equate to 0.175 seconds

7 0
2 years ago
Cuantos días tiene un año
Arte-miy333 [17]

Answer: 365 dias

Explanation:

4 0
2 years ago
During the _____it is important to figure out how the test will be scored.
vampirchik [111]
A test preview is the answer
3 0
3 years ago
Other questions:
  • A retail company assigns a $5000 store bonus if monthly sales are $100,000 or more. Additionally, if their sales exceed 125% or
    5·1 answer
  • Where should you look to find contact information about a company? I. on the company website II. at your local library III. in t
    11·2 answers
  • What is a VIN and what role does it play during a criminal investigation? Explain how a VIN could help in a bomb and/or arson ca
    12·1 answer
  • A​ ___________ identifies the content and purpose of the​ visual, along with whatever label and number​ you're using to refer to
    15·1 answer
  • What is logical memory?
    15·1 answer
  • What happens when two computers use the same IP address?
    15·1 answer
  • How acid rain pollution will affect the food chain
    15·2 answers
  • What relationship do MP3s and MP3 players have with video files?
    11·1 answer
  • A program has a infinite while loop. How can you interrupt it?
    7·1 answer
  • A natural language processor comes across a sentence that contains the word “weightless.” The morphology component identifies th
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!