Question

write a code to multiply two integer arrays (each with N numbers). Monitor the time to...

write a code to multiply two integer arrays (each with N numbers). Monitor the time to run that code with the following N: 50, 100, 200, and 400

=================

You can write in either C or in Java,

Provide correct solution to get upvote,

Thanks

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

The source code in Java Programming Language is given below:

import java.util.*;

public class Main
{
public static void main(String[] args)
{  
//variable declaration
long startTime, executionTime;
  
//initialize with start time
startTime = System.nanoTime();
  
final int N = 50;
  
//array declaration
int[] a = new int[N];
int[] b = new int[N];
long[] c = new long[N];
  
  
//multiply two array
for (int i = 0; i < N; i++)
{
       c[i] = a[i] * b[i];
}
  
//calculate execution time
executionTime = System.nanoTime() - startTime;
  
//display the result
System.out.println("Size of array: "+N);
System.out.println("Execution time: " + executionTime +" nano seconds");
}          
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
write a code to multiply two integer arrays (each with N numbers). Monitor the time to...
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
  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

  • Java question Given an array of integer numbers, write a linear running time complexity program in...

    Java question Given an array of integer numbers, write a linear running time complexity program in Java to find the stability index in the given input array. For an array A consisting n integers elements, index i is a stability index in A itf ATO] + A[1] + +A[iI-1] Ali+1]+ Ali+2] +... + A[n-1]; where 0 <i< n-1 Similarly, 0 is an stability index if (A[1] A[2]A[n-1]) 0 and n-1 is an stability index if (A[0] A[1]+... A[n-21) 0 Example:...

  • Given an array of integer numbers, write a linear running time complexity program in Java to...

    Given an array of integer numbers, write a linear running time complexity program in Java to find the stability index in the given input array. For an array A consisting n integers elements, index i is a stability index in A if A[0] + A[1] + ... + A[i-1] = A[i+1] + A[i+2] + ... + A[n-1]; where 0 < i < n-1. Similarly, 0 is an stability index if (A[1] + A[2] + ... + A[n-1]) = 0 and...

  • Given two integer arrays, A and B of length n each, write an efficient algotihm to...

    Given two integer arrays, A and B of length n each, write an efficient algotihm to find an integer that occurs the same number of times in both A and B. extra: solve this recurrence: T(1) = 1; T(n) = T(n/4) + n

  • JAVA CODE Write a JAVA program to do the following. Input an integer x. (Should work...

    JAVA CODE Write a JAVA program to do the following. Input an integer x. (Should work with “big” numbers.) Create a completely-skewed BST S containing 1, 2, . . . , x. Create a BST R containing x integers without repetitions gen- erated at random. (To minimize the risk of repetitions, you can multiply the value returned by random() by a big number.) Given that the numbers are generated uniformly at random, the tree will likely be balanced. Measure the...

  • i need help writing these programs in c++ format 1. Enter two integer arrays: array1-129, 0,...

    i need help writing these programs in c++ format 1. Enter two integer arrays: array1-129, 0, -56, 4, -7 and array2-19, 12, -36, -2, 12 3. Write the code to form and display another array array3 in which each element is the sum of numbers in the position in both arrays. Use pointers and functions: get array0. process arrays0 and show array0 (50 points) 2. Enter a positive 5-digit integer via the keyboard. Display each digit and fol- lowed by...

  • Write a C program requesting the user to input two integer numbers and then requesting the...

    Write a C program requesting the user to input two integer numbers and then requesting the user to either add, subtract, or multiply the two numbers (choose 0 to add, 1 to subtract, or 2 to multiply. Declares three separate functions for these choices to come after main(). Program needs to use a pointer to these three functions to perform the requested action. Must print to output.

  • Write a program that reads two integer arrays each of size 10 then find and print...

    Write a program that reads two integer arrays each of size 10 then find and print the inner product of the arrays.  Inner product can be performed by multiplying each element of one vector by the corresponding element in the second vector that has the same index, and summing all the products. For example: A[5]= {1,2,3,4,5} B[5]= {2,0,3,1,5} Inner product = 40

  • 1. Write a Java program to implement Counting Sort and write a driver to test it....

    1. Write a Java program to implement Counting Sort and write a driver to test it. Note: use random number generator to generate your input with n = 10, 50, and 100. Verify that the running time is O(n). 2. Write a Java program to implement Bucket Sort and write a driver to test it. Note: use random number generator to generate your input with n = 10, 50, and 100. Verify that the running time is O(n). 3. In...

  • Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer...

    Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer array of length n, where each value is between is 1 and n, and displays true if there are any duplicate values, false otherwise. CODE IN JAVA and NO IMPORT STATEMENTS CAN BE USED

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