Question
programing C,already write part of code

(a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This functi
Write a function dot.product that receives two arrays of real numbers and the number of elements stored in the (both of) the
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#define SIZE 50

//pre defining the function to be used
void read_numbers(double[],double[]);
void print_array(int,double[],double[]);
double dot_product(int,double[],double[]);

//making length of array (n) global
int n=0;


void main(){
   double sum;
   double array_one[SIZE],array_two[SIZE]

;//calling the three functions one after other
   read_numbers(array_one,array_two);
   print_array(n,array_one,array_two);
   sum = dot_product(n,array_one,array_two);

//printing the return dot product of the function dot_product

   printf("The dot product of these two vectors is: %.2lf\n",sum);
}

//functions to read user entered inputs vectors

void read_numbers(double array_one[],double array_two[]){
   int i=0;
   printf("Enter the number of elements in the array\n");
   scanf("%d",&n);
   printf("Fill the first array\n");
   for(i=0;i<n;i++){
       printf("Enter a number 0 to end input\n");
       scanf("%lf",&array_one[i]);
   }
   printf("Fill the second array\n");
   for(i=0;i<n;i++){
       printf("Enter a number 0 to end input\n");
       scanf("%lf",&array_two[i]);
   }
}

//print the user entered vectors values


void print_array(int n,double array_one[],double array_two[]){
int i=0;
printf("The values of first vector are\n");
for(i=0;i<n;i++){
   printf("%.2f\n",array_one[i]);
}
printf("The values of second vector are\n");
for(i=0;i<n;i++){
   printf("%.2f\n",array_two[i]);
}
}

//produce the dot product of user entered vector values and return the dot product to main function

double dot_product(int n,double array_one[],double array_two[]){
    int i=0;
    double dotsum;
    for(i=0;i<n;i++){
        dotsum+=array_one[i]*array_two[i];
    }
    return dotsum;
}

nter the number of elements in the array ll the tist array nter a number 0 to end input nter a number 0 to end input 4.2 nter

Add a comment
Know the answer?
Add Answer to:
programing C,already write part of code (a) Write a function print.array that receives an array of...
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
  • ** C++ LANGUAGE ** Write a function that will implement each Fibonacci number with the help...

    ** C++ LANGUAGE ** Write a function that will implement each Fibonacci number with the help of an integer array of size 100 (elements of this array will be digits of the Fibonacci number). When the function is called to find , it will calculate all Fibonacci numbers from to using the basic formula . To add two Fibonacci numbers, the function will add elements of two arrays corresponding to and and store their sums in the array corresponding to...

  • 7eatng that function Write a C++ program that does the following: Fill an array of 123...

    7eatng that function Write a C++ program that does the following: Fill an array of 123 elements using srand) and rand) with random numbers between 150 and 667. Fill an array of 123 elements with random numbers between 150 and 667. Using a loop. Fill an array of 123 elements with random numbers between 150 and 667. Using a for loop Use a void function to fill an array of 123 elements with random numbers between 150 and 667, Possible...

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

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

  • In C++, write a complete program that receives a series of student records from the keyboard...

    In C++, write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string. The program should prompt for the number of records to be entered and then receive user input on how many records are to...

  • Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters:...

    Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters: an unsigned doubleword array and the length of the array. The function must return the value of the largest array member in eax. Preserve all registers (except eax) that are modified by the function. Write a test program in main that calls findLargest three times, each call using a different array with different lengths. Function called countHits Write a function called named countHits that...

  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • In C++ Write a function that receives an integer array with its size and determines whether...

    In C++ Write a function that receives an integer array with its size and determines whether the array is already sorted in increasing order. Write a test program (main function) that prompts the use to enter a list and displays whether the list is sorted or not. The first number in the input indicates the size of the list. Assume the maximum list size is 20.

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