Question

In C programming language write a function that takes two arrays as input m and n...

In C programming language write a function that takes two arrays as input m and n as well as their sizes: size_m and size_n, respectively.
Then it checks for each element in m, whether it exists in n.
The function should update a third array c such that for each element in m:
the corresponding position/index in c should be either
1, if this element exists in m, or
0, if the element does not exist in n

Homework Answers

Answer #1

#include <stdio.h>

//function to udpate array for each element
//1, if this element exists in m, or
//0, if the element does not exist in n
void updateArray(int m[][3], int n[][3], int size_m, int size_n)
{
//array declaration
int newArr[size_m][size_m];
  
//update the newArr
for(int i=0; i<size_m; i++)
{
for(int j=0; j<size_m; j++)
{
if(m[i][j] == n[i][j])
newArr[i][j] = 1;
else
newArr[i][j] = 0;
}
}
//display the new array
for(int i=0; i<size_m; i++)
{
for(int j=0; j<size_m; j++)
{
printf("%d ", newArr[i][j]);
}
printf("\n");
}
}

int main()
{
//array declaration and initialization
int m[][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int n[][3] = {{1, 12, 3}, {10, 11, 6}, {17, 8, 19}};
  
//function calling
updateArray(m, n, 3, 3);
  
return 0;
}

OUTPUT:

1 0 1
0 0 1
0 1 0


Know the answer?
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
Similar Questions
In C programming language write a function that takes an integer n as input and prints...
In C programming language write a function that takes an integer n as input and prints the following pattern on the screen: 1 (n times) 2 (n-1 times) .n (1 time) For example, if n was 5, the function should print 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
In Python language: Create a function that takes as input two numbers, m and n, m<n,...
In Python language: Create a function that takes as input two numbers, m and n, m<n, and returns an m×n list-of-list-of-numbers. Each element of the outer list will be a list of consecutive integers, beginning with 1 and ending with n−1. If you're feeling bold, try to use list comprehension.
C++ Write a function that takes in 3 arguments: a sorted array, size of the array,...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question. c++ code
***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes...
***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes two functions, f and g, and a list xs as parameters and evaluates to a list. f will be a function that takes one parameter and evaluates true or false. g will be a function that takes one parameter and evaluates to some output. The result of update-if should be a list of items such that if x is in xs and (f x)...
How would I write this function in C programming language? Function header: int input(int *a, int...
How would I write this function in C programming language? Function header: int input(int *a, int *b, int *c) This function should attempt to input 3 integers from the keyboard and store them in the memory locations pointed to by a, b, and c. The input may not be successful in reading all three values. The function should return the number of values that were successfully read.
Write a function called matches that takes two int arrays and their respective sizes, and returns...
Write a function called matches that takes two int arrays and their respective sizes, and returns the number of consecutive values that match between the two arrays starting at index 0. Suppose the two arrays are {3, 2, 5, 6, 1, 3} and {3, 2, 5, 2, 6, 1, 3} then the function should return 3 since the consecutive matches are for values 3, 2, and 5. in C++ Im confused how to start this, any hints are great and...
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
USE C++ Write a function named find that takes a pointer to the beginning and a...
USE C++ Write a function named find that takes a pointer to the beginning and a pointer to the end (1 element past the last) of an array, as well as a value. The function should search for the given value and return a pointer to the first element with that value, or the end pointer if no element was found.
(C++) Write a function called triple that takes an array of integers as a parameter as...
(C++) Write a function called triple that takes an array of integers as a parameter as well as the length of the array. It should triple each value in the array. The function should not return anything. (Note that the contents of the array WILL be modified.)
Write a function in Matlab that takes as input the number of iterations k, the size...
Write a function in Matlab that takes as input the number of iterations k, the size n, and a sparse matrix A. Have this function run the Power method for k iterations on an initial guess the vector of 1’s and output the dominant eigenvalue and its corresponding eigenvector. Use only basic programming. Write out or print out your function.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT