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
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
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
Write a function that takes in 3 arguments: a sorted array, size of the array, and...
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.
***************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)...
C++ Write a program that takes two integer arrays of different sizes from the user (this...
C++ Write a program that takes two integer arrays of different sizes from the user (this means that the user can tell the program the size of each array), and then computes the intersection and union of those arrays. Note: the arrays can be of different lengths and the intersection/union should have unique elements in sorted order. Use pointer notation of arrays for this question. Eg: *(arr+1) [10]
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...
Write a program that takes two integer arrays of different sizes from the user (this means...
Write a program that takes two integer arrays of different sizes from the user (this means that the user can tell the program the size of each array), and then computes the intersection and union of those arrays. Note: the arrays can be of different lengths and the intersection/union should have unique elements in sorted order. Use pointer notation of arrays for this question. Eg: *(arr+1) [10] C++
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT