Requirements: You must use pointers to process all arrays.
Code a C function that accepts pointers to two arrays of integers and their respective sizes. This function should check and count how many matchings entries in both arrays and return the count back to main for display. (important! Matchings entries do not have to be located in the same position and you are required to assume that the two arrays are of different sizes…also assume no duplicate within either arrays)
#include<stdio.h>
int count(int a[],int b[],int alen,int blen)
{
int i,j,match=0;
for(i=0;i<alen;i++)
{
for(j=0;j<blen;j++)
{
if(a[i]==b[j])
{
match++;
}
}
}
return match;
}
int main()
{
int a[]={1,5,56,3,4};
int b[]={4,3,7,5,8,10};
printf("matches=%d\n",count(a,b,5,6));
}
Explanation:
This program will take O(n2) complexity,because we are checking each element of first array with each element of second array.
If any match entries is occured it counts the match.And at last it will return total count of the match entries in both arrays.
Here passing pointers to the function means passing the addresses,for arrays the name of the array points first element in the array,that is why we pass array name a and b are passed to the function count(a,b,5,6)
Requirements: You must use pointers to process all arrays. Code a C function that accepts pointers...
Write a C++ program that will test function described below that use pointers and dynamic memory allocation. Functions: You will write the function described below. Then you will call them from the main function, to demonstrate their correctness. concat_array: takes two int arrays and the arrays' sizes as arguments (that's 4 arguments). It should create a new array big enough to store both arrays. Then it should copy the contents of the first array to the new array, and then...
29. (20 points) Write the complete C++ program that implements the following program, as if you were turning this in for homework. Your program should have a commented header (your name, etc), comments within the program and a well-built display for the output. Don't forget the pre-processor commands Define an array called nums with a maximum of 20 integers, and fill the array with numbers, recei the keyboard (prompt for the numbers.) In this program, exactly 20 integers will be...
C program that uses
pointers as function arguments to do the
following:
To exemplify pointers, we will be doing quadratics. Remember that a quadratic expression is of the form: ax2 + bx + c where a. b, c are constant and a is not 0. You will scan in the values a. b. and c. With these values, you will write three functions: quadraticFormula quadraticVertex quadratic Info The first function will perform the quadratic equation to find the roots of...
C++ Project - Create a memory game in c++ using structs and pointers. For this exercise, you will create a simple version of the Memory Game. You will again be working with multiple functions and arrays. You will be using pointers for your arrays and you must use a struct to store the move and pass it to functions as needed. Program Design You may want to create two different 4x4 arrays. One to store the symbols the player is...
write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...
In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater or equal to the average and fill out the second array with these numbers. You need to design the function. I tried this code but the errors returned were: expression must have a constant value #include<iostream> using...
This lab continues to work with C++ arrays and introduces vectors 1) First, most code that works on arrays can solve a problem using a single loop. One problem where this is not true is if you need to check if there are any duplicates in the array. ·In a file called duplicates.cpp write a function hasDups(string strs[], int numStrs) that returns true if there are any duplicates in the names array ·Write main() to simulate reading in a single ranked...
IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...
Hello I need help with this program. Should programmed in C!
Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
Please help code in c++ and use the answers you get from question 1
and 2 into the 3rd answer! Question 1 is first, question 2 is in
the middle, question 3 is last
Input Array (10 pts) te a function only (no main) that takes an array of doubles as a parameter as well as another integer rray. Create a for loop that asks the user to input any real number between-100 and r each element of the array....