
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Relational Operator (Re-visited) Logical Operator (Re-visited) While Loop Do While Loop Nested If-else 2
Two logical operators
Situation : Check whether an integer K is even and divisible by 5 --------Header Files---------- main(){ int K =20; if(K%2==0&&K%5==0) cout<<“K is divisible by 5 and is also even”; else cout<<“Condition Failed”; }
Situation: Check that two integers A and B both are even Sol: main(){ int A=10,B=25; if((A%2==0)B && (B%2==0) ) cout<<“Both are even “; else cout<<“Condition Failed”; }
Situation: Check that two integers A and B both are even Sol: main(){ int A=10,B=25; if((A%2!=0)B || (B%2!=0) ) cout<<“Condition Failed”; else cout<<“Both are even “; }
Consider: count = 0; // Initialization while (count < 3) // Loop Condition { cout << "Hi "; // Loop Body count++; // Update expression } Loop body executes how many times?
2-
Formal syntax: if (<boolean_expression>) <yes_statement> else <no_statement> Note each alternative is only ONE statement! To have multiple statements execute in either branch we use { }
Not new, just different indenting Syntax:
If slaray is between 30000 and 50000 tax = 5 % otherwise if marks is between 50,000 and 100,000 tax =10% otherwise if marks is between 100,000 and 200, tax=15%
int marks; int tax; If(marks>=30,000 && marks<50,000) else If(marks>=50,000 && marks<100,000) else If(marks>=100,000 && marks<200,000)