





















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The key points in the Advanced Algorithms are:Control Statements, Switch, While, Do-While, Execute a Statement, Depending, Bank Account, Condition Holds, Many Statements, Sell Dollar
Typology: Slides
1 / 61
This page cannot be seen from the preview
Don't miss anything!






















































we want to execute a statement depending on a condition? e.g. If there is enough money in the bank account, give the money we want to execute one statement when a condition holds and another statement when a condition does not hold? e.g. If dollar is high, sell dollar. Otherwise, buy dollar. we want to select from many statements according to one or more criteria ( selection ). e.g. If dollar is high and euro is low, sell dollar and buy euro. If dollar is low and euro is high, sell euro and buy dollar. If both of them are high, sell both and buy YTL.
if (< condition >) <s tatement_true> ; else <s tatement_false> ;
if (< condition >) <s tatement_true> ;
test condition
true statements
true
next statement
false
false statements
Boolean type and expressions
Values are true or false bool is a built-in value type like int, double
int degrees; bool isHot = false;
Console.WriteLine("enter temperature: “); degrees = Convert.ToInt32(Console.ReadLine()); if (degrees > 35) { isHot = true; }
if…else statement.
Console.WriteLine( grade >= 60? "Passed" : "Failed" );
8
A B A || B A && B true true true true true false true false false true true false false false false false
A! A true false false true
if (num >= 0 && num <= 100) Console.Write("number is in the range"); else Console.Write("number is out of range");
if (! (num >= 0 && num <= 100) ) Console.Write("number is out of range"); else Console.Write("number is in the range");
if (num < 0 || num > 100) Console.Write("number is out of range"); else Console.Write("number is in the range");
Operator Explanation Associativity
assignment operators right-to-left
90 .. 100 A 80 .. 89 B 70 .. 79 C 60 .. 69 D 0 .. 59 F otherwise F
if ( grade >= 90 ) Console.WriteLine( "A" ); else if ( grade >= 80 ) Console.WriteLine( "B" ); else if ( grade >= 70 ) Console.WriteLine( "C" ); else if ( grade >= 60 ) Console.WriteLine( "D" ); else Console.WriteLine( "F" );
16
if (count != 0) { if (scores/count < 60) { Console.WriteLine("low average"); } }
if ( x % 2 == 0) { if ( x < 0 ) Console.WriteLine("{0} is an even, negative number“, x); } else { Console.WriteLine("{0} is an odd number“, x); }