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 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.
Using Arduino a) write a program that uses two potentiometers to adjust the values displayed on...
Using Arduino a) write a program that uses two potentiometers to adjust the values displayed on the serial monitor. Have the two values displayed side by side via the serial monitor and each range from 0 to 255
Write a program in C that sorts 3 given numbers, defined as (a,b,c) from highest to...
Write a program in C that sorts 3 given numbers, defined as (a,b,c) from highest to lowest. I already have this code finding the maximum. Need to just add the sorting code onto it. int A, B, C; A = 4; B=3; C=7; Max = A If (B > max) { Max = B; } Else if (c > max) { Max = c; }
Write a program that implements the A* algorithm to find a path from any two given...
Write a program that implements the A* algorithm to find a path from any two given nodes. You may use any of the following languages: C++, C#, Java, ActionScript. Problem Overview & Algorithm Description In a fully-observable environment where there are both pathable and blocked nodes, an agent must find a good path from their starting node to the goal node. The agent must use the A* algorithm to determine its path. For this program, you must use the Manhattan...
arduino programing Question 1: write an APL program that will print the following output on the...
arduino programing Question 1: write an APL program that will print the following output on the serial monitor 10 times only.   Output:  1 2 3 4 5 Question 2: write an APL program that will turn the traffic lights on and off by taking input from the Serial port working at 11500 bits processing rate. Use r or R for RED LIGHTS, y or Y for YELLOW LIGHTS and g or G for GREEN LIGHTS.    Question 3: write an APL...
write a C++ program that uses function swap (a,b) to enter two real numbers from the...
write a C++ program that uses function swap (a,b) to enter two real numbers from the keyboard and uses function min_max(a,b) to return a to be the smaller of the two numbers entered always.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT