Question

In: Computer Science

In arduino: 1.Given two Arrays A= {2,4,7,8,3) and B={11,3,2,8,13). Write a program that find the numbers...

In arduino:

1.Given two Arrays A= {2,4,7,8,3) and B={11,3,2,8,13). Write a program that find the numbers into A but not in B. For the example C=A-B= {4,7} Print the values (Use for loops)

2.Create a vector of five integers each in the range from -10 to 100 (Prompt the user for the five integer x). Perform each of the following using loops:

a) Find the maximum and minimum value

b)Find the number of negatives numbers

Print all results

Solutions

Expert Solution

Ans 1

void setup() {
        int  A[] = {2, 4, 7, 8, 3};
        int  B[] = {11, 3, 2, 8, 13};
        int n = sizeof(A)/sizeof(A[0]);   //finding sizeof both the arrays
        int m = sizeof(B)/sizeof(B[0]);
        for(int i = 0;i<n;i++){
                int flag = 0; //this flag is used to check whether we got a matching element or not
                for(int j = 0;j<m;j++){
                        if(A[i] == B[j]){
                                flag = 1; // if matching element is found that means this is the commom element
                        }
                }
                if(flag == 0) //no matching element found
                        printf("%lld ", A[i]);
        }
}

Ans 2

void setup() {
        int arr[5];
        int x;
        for (int i = 0; i < 5; i++) {
                cout << "Please enter " << i+1 << "th value: " << endl;
                cin >> x;
                arr[i] = x;
        }
        int mxm = -11;
        int mnm = 101;
        for (int i = 0; i < 5; i++) {
                mxm = max(mxm, arr[i]);
                mnm = min(mnm, arr[i]);
                if (arr[i] < 0)
                        cout << arr[i] << " ";
        }
        cout << endl;
        cout << "Maximum value is " << mxm << endl;
        cout << "Minimum value is " << mnm << endl;
}

Related Solutions

Given two arrays: A[0..m-1] and B[0..n-1]. Find whether B[] is a subset of A[] or not....
Given two arrays: A[0..m-1] and B[0..n-1]. Find whether B[] is a subset of A[] or not. Both the arrays are not in sorted order. It may be assumed that elements in both array are distinct. Design an O(n) time algorithm that solves this problem. Provide pseudocode Ex: Input: A[] = {11, 1, 13, 21, 3, 7}, B[] = {11, 3, 7, 1} Output: B[] is a subset of A[] Input: A[] = {1, 2, 3, 4, 5, 6}, B[] =...
Write a program that takes two integer arrays a and b of size n from the...
Write a program that takes two integer arrays a and b of size n from the user, the use a method product to find the product of a and b and return the results after storing them in an array c, then prints the returned results to the screen. (Note: c[i] = a[i] * b[i], for i = 0, ..., n-1) Sample Output: Enter the size of your arrays: 5 Enter the integer values of the first array a: 1...
. As input you are given two arrays: an array of numbers ? and an array...
. As input you are given two arrays: an array of numbers ? and an array ? of queries where each query is a target number. The array ? is unsorted and may contain duplicates. Your goal is, for each query ? in the array ?, count the number of pairs in the array ? that sums up to ?; that is, the number of distinct pairs of indices [?, ?], with ? < ?, such that ?[?] + ?[?]...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
write a program to find the maximum possible sum such that no two chosen numbers are...
write a program to find the maximum possible sum such that no two chosen numbers are adjacent either vertically, horizontally, or diagonally. code in java
Write a C++ program Given fuzzy sets A and B, find complement A, A ∪ B,...
Write a C++ program Given fuzzy sets A and B, find complement A, A ∪ B, and A ∩ B A = {0.2 : a, 0.7 : b, 0.5 : c, 0.01 : k, 0.98 : z} and B = {0.42 : a, 0.6 : b, 0.5 : h, 0.1 : k, 0.44 : m, 0.8 : z}
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are...
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are divisible by 3. Arrange these numbers in a list called “result”. Hint: similar to page 9 in the slides.
{ /* Write a program in C++ to find the perfect numbers between 1 and 500....
{ /* Write a program in C++ to find the perfect numbers between 1 and 500. The perfect numbers between 1 to 500 are: 6 28 496*/    int sum = 0;    int i = 1;    int j = 1;    for (i ; i <= 100; i++)    {        for (j; j <= 100; j++)        {            if (j < i)//Line 55            {                  ...
. (a) Write a C++ program to find Fibonacci numbers. (For the definition of Fibonacci numbers...
. (a) Write a C++ program to find Fibonacci numbers. (For the definition of Fibonacci numbers and the recursive formula please refer to problem 5 of Chapter 2 at page 81 in the text-book.) The program asks the user to input an integer and outputs the corresponding Fibonacci number. For example, if the user inputs 4, the program outputs the fifth Fibonacci number, which is 3. Introduce two local variables in the recursion function (suppose we call it fib(n)), one...
Write Arduino program to implement wiring three momentary switches to the Arduino board
Write Arduino program to implement wiring three momentary switches to the Arduino board
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT