What is the purpose of the following code? [code] void setup() { Serial.begin(9600); } void loop() { int a[4]={1,2,3,4}; int

What is the purpose of the following code?
Code:
void setup() {
    Serial.begin(9600);
}
void loop() {
    int a[4]={1,2,3,4};
    int search_item=2;
    int i;
    for(i=0;i<4;i++) {
        if(a[i]==search_item) {
            Serial.print(“Found!”);
        }
    }
}
A. Search
B. Sort
C. Delete
D. Append
 
Answer: A
Explanation: The code given above performs continuously checks whether a number called “search_item” is present in the array given or not. This operation is called a Linear Search wherein the search operation sweeps the array linearly from one end to another and checks if an item is present or not.
 

Tìm kiếm

Back
Top