Question

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

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

SOURCE CODE IN C:

#include <stdio.h>

int main()

{

int A[10], B[10]; //declaring arrays

//input array A

printf("Enter elements of first array: ");

for(int i=0; i<10; i++)

scanf("%d", &A[i]);

//input array B

printf("Enter elements of second array: ");

for(int i=0; i<10; i++)

scanf("%d", &B[i]);

//finding inner product of A and B

int innerProduct=0;

for(int i=0; i<10; i++)

innerProduct+=A[i]*B[i];

//output inner product

printf("The inner product is %d.\n", innerProduct);

return 0;

}

OUTPUT:

> clang-7 -pthread -lm -o main main.c } ./main Enter elements of first array: 1 2 3 4 5 6 7 8 9 10 Enter elements of second a

Regards!

Add a comment
Know the answer?
Add Answer to:
Write a program that reads two integer arrays each of size 10 then find and print...
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
  • Problem 1: Consider 2 integer arrays, x and y, of the same size (assume size =...

    Problem 1: Consider 2 integer arrays, x and y, of the same size (assume size = 10). Initialize array x with random numbers between 1 and 100. Write code that fills array y with values such that each element of y is the corresponding value of x multiplied by its index.

  • Write a program that first reads an integer for the array size, then reads numbers into...

    Write a program that first reads an integer for the array size, then reads numbers into the array, computes their average, and finds out how many numbers are above the average. Make sure to include pointer syntax. Example output: Enter array size: 10 10 random numbers between 1 and 10 generated are: 2 8 5 1 10 5 9 9 3 5 The average is: 5.7 Number of items above the average = 4 C++ Code only.

  • Write a program that works with two arrays of the same size that are related to...

    Write a program that works with two arrays of the same size that are related to each other in some way (or parallel arrays). Your two arrays must be of different data types. For example, one array can hold values that are used in a formula that produces the contents of the second array. Some examples might be:  from a previous program, populations and the associated flowrates for those populations (an int array of populations and a double array...

  • Suppose we have two integer arrays with the same type, write an AL program to check...

    Suppose we have two integer arrays with the same type, write an AL program to check whether or not there are two integers, one from each array, with sum equal to zero. If there are such integers exist, print out all such combinations to the console window, otherise, print out "No integers in these two arrays, one from each array, with sum equal to zero." to the console window. December 3. 2018 For example, suppose we have the following two...

  • C++ Write a program based on 8_lb that reads in the integer data from "input.txt" into...

    C++ Write a program based on 8_lb that reads in the integer data from "input.txt" into a vector. Please prompt for the file name and append the "txt". Then create another vector where each element is the original vector times 10. Create a variable total and sum up the numbers from the second vector. The total should be 17510. Then write the data from the original vector and the 10 times vector to a file. See output.txt for the format....

  • 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...

  • Write a mips program that defines two integer array that are pre-sorted and the same size...

    Write a mips program that defines two integer array that are pre-sorted and the same size (e.g., [3, 7, 9, 11, 15, 21] and [1, 4, 6, 14, 18, 19]) and a function merge that takes the two arrays (and their size) as inputs and populates a single array of twice the size of either input array that contains the elements of both arrays in ascending order. In the example arrays given, then output would be [1, 3, 4, 6,...

  • Write a program that reads a string from the keyboard and computes the two arrays of...

    Write a program that reads a string from the keyboard and computes the two arrays of integers upperCase, and lowerCase, each of size 26. The first one represents the frequency of upper case letters and the second one represents the frequency of lower case letters in the input string. After computing these arrays, the program prints the frequencies in the following format: The frequency of the letter A= The frequency of the letter B= Assume the input string contains only...

  • For c++ Write a complete C++ program and declare 2 arrays type double size 5. The...

    For c++ Write a complete C++ program and declare 2 arrays type double size 5. The name of the first array is Salary and the name of the second array is Tax. Use a for loop loop and enter 5 salaries type double into array Salary. Then multiply each element of array Salary by .10 (10 percent), and save the result into array Tax. Print/display the content of both arrays. Hint: the content of array Tax is 10% percent of...

  • The method generate() will produce integer arrays of a random size between 10 and 20 members. ...

    The method generate() will produce integer arrays of a random size between 10 and 20 members. The method print() will print out the members of an integer array input. The method insert() will accept two arrays as inputs. It will produce a new array long enough to contain both arrays, and both input arrays should be inserted into the new array in the following manner: select a random member of the first array, and insert every member of the second...

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