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 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
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;
}