Question

Write a C function named add with the following parameters: three float arrays a, b and c, each of the three arrays is a two

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

The code is commented and variables are named accordingly.

Code:

#include <stdio.h>

// Declaring size of array globally
int m;
int n;
void add_arrays(float a[m][n],float b[m][n],float c[m][n]){

//Adding arrays
for(int i=0;i<m;i++){

for(int j=0;j<n;j++){

c[i][j]=a[i][j]+b[i][j];

}

}

}
int main(void) {

m=2;
n=3;
float a[2][3]={{9,10,7},{15.6,20.4,5.1}};
float b[2][3]={{1.2,2,3.4},{3.3,2,1}};
float c[2][3];
  
//calling function for adding arrays
add_arrays(a,b,c);
  
printf("The sum is: \n\n");
//printing results
for(int i=0;i<m;i++){

for(int j=0;j<n;j++){

printf("%f ",c[i][j]);

}
printf("\n");

}
   // your code goes here
   return 0;

}

Code Screenshot:

#1nclude <stdio 3 // Declaring size of array globally int m 5 int n 6 void add arrays(float a m] In],float b[m]In,float c[m][

Output:

The sum is: 10.200000 12.000000 10.400000 18.900000 22.400000 6.100000

Add a comment
Know the answer?
Add Answer to:
Write a C function named add with the following parameters: three float arrays a, b and c, each of the three arrays is...
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
  • Write a C function named add with the following parameters: three float arrays a, b and...

    Write a C function named add with the following parameters: three float arrays a, b and c, each of the three arrays is a two dimensional array. The function should add the first two arrays a and b (entry by entry), storing the results in the third array c. In the main function, call the add function with appropriate values. The main function should print the sum of the two arrays stored in the third array. Sample run: float al...

  • c++ write a function that has 3 parameters, two arrays of integers of the same size...

    c++ write a function that has 3 parameters, two arrays of integers of the same size , and the size of the arrays. the function should add the two arrays and store the results in a third array, then print out the contents of the third array name it arraya

  • Write three functions, float getNum(), float add(float, float), void outSum(float); that asks user for two numbers,...

    Write three functions, float getNum(), float add(float, float), void outSum(float); that asks user for two numbers, finds the sum of two numbers, and displays the sum repeatedly in a main program until the user enter "0" for either one of the numbers. (In C++)

  • C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array...

    C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array named f, and one double array named d, each of size M. (b)Declare array x with N of those structs. (c)Write a void function to traverse array x (using a pointer) assigning to each element in each array d (in each struct in array x) the sum of the corresponding elements in arrays i and f (in the same struct). Use 3 pointers (of...

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • Write a C program that inputs 5 elements into each of 2 integer arrays. Add corresponding...

    Write a C program that inputs 5 elements into each of 2 integer arrays. Add corresponding array elements, that array1 [0] + array2[0], etc. Save the sum into a third array called sumArray[]. Display the sum array. Submit your and the input and output of the complete execution.

  • Write a function template named summarray, with two parameters: and array called are and an int...

    Write a function template named summarray, with two parameters: and array called are and an int holding the number of elements in arr. The function should return the sum of the elements in arr. this template must work for double or int arrays. Show a sample function call to the template function you wrote. What would you have to do to use the templates sumArray function with an array of objects of a custom class?   

  • using C , comments will be appreciated. Question1 Write down an function named bitwisedFloatCompare(float number1, float...

    using C , comments will be appreciated. Question1 Write down an function named bitwisedFloatCompare(float number1, float number2)that tests whether a floating point number number1is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differingbit is encountered. The fact that this can be done easily is the main motivation for biased exponent notation. The function should return 1 if number1...

  • Given two 2-dimensional arrays, A and B, calculate the three arrays: A + B, A*B and...

    Given two 2-dimensional arrays, A and B, calculate the three arrays: A + B, A*B and A*B-1 . That is to say find the sum of the two arrays, the outer-product of the two arrays and the outer-product of A times B inverse. You can use the procedure illustrated on the web site: https://www.thecrazyprogrammer.com/2017/02/c-c-program-find-inverse-matrix.html (Links to an external site.) make the arrays 3X3, choose any values you wish make sure the determinant of B is not zero, if so change...

  • Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel...

    Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel arrays of different types and the third argument is of type size_t representing the size of both arrays. The function DisplayMin must work when called with various types of actual arguments, for example string DisplayMin(string names[], int calories[], int size) or int DisplayMin(int calories[], float prices[], int size). (Parallel Arrays are two arrays whose data is related by a common index. For example: with...

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