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
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 programming Write a function that takes in a 2D char array (string array) and return...
C programming Write a function that takes in a 2D char array (string array) and return a 1D char array with all the elements connected together Hint: strlen(-char*-) //returns the length of a string strcat(-char* accum-, something to add) //works like string+= in java
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.
Write a function called TaylorSin.m that takes as input an array x, and positive integer N,...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N, and returns the Nth Taylor polynomial approximation of sin(x), centered at a = 0. The first line of your code should read function s = TaylorSin(x,N) HINT: in computing k!, use kfact = k*(k-1)*kfact since you are counting by 2
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
Write a c++ function which takes two parameters: an array of ints and an int size...
Write a c++ function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void printSome(const int array[], int size);
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT