What is the output of the code given below? [code] void setup() { Serial.begin(9600); } void loop() { int a=10; int b=12;

Minh Tung

New member
What is the output of the code given below?
Code:
void setup() {
    Serial.begin(9600);
}
void loop() {
    int a=10;
    int b=12;
    int c=13;
    if(a>b && a>c) {
        Serial.println(a);
    }
    else if(b>a && b>c) {
        Serial.println(b);
    }
    else if(c>a && c>b) {
        Serial.println(c);
    }
}
A. 10
B. 12
C. 13
D. null
 
Answer: C
Explanation: The above code uses the if-else-if structure to find out the maximum of three integers. We must use 3 conditional blocks here to compare each value with the other one such that we can find the integer which is greater than the both the other integers.
 

Tìm kiếm

Back
Top