Section 3
Section 3
Programming
Using C#
Lab 3
By:
Eng.Omar Islam
Lab Objectives
Definitions:
• 1- Algorithm: An algorithm is a detailed, step-
by-step set of instructions to solve a specific
problem.
• Start
• Get the first number (Input)
• Get the second number (Input)
• Add the two numbers (Process)
• Display the sum (Output)
• End
Flowchart
Code
Expression
Solution:
c = 3 + 6 + 4 + 5 = 18
a=4
b=5
c = 18
Ans Cont.
• a=3 b=6 c=0
• c = (a++) + (++b) + a + b
(a++): a will be incremented by one and the old value will be used
(++b): b will be incremented by one and the new value will be used
Solution:
c = 3 + 7 + 4 + 7 = 21
a=4
b=7
c = 21
Ans Con.
• (--b): b will be decremented by one and the new value will be used
Solution:
c = 3 + 5 + 4 + 5 = 17
a=4
b=5
c = 17
Practice 1
||
This is known as the “Logical OR” operator. It checks whether
either of the condition on both sides is true.
!
This is known as the “Logical NOT” operator. It just changes
the current boolean value to its opposite.
Example
Compound Assignment
Operator Precedence
Shifting
• Suppose that a = 3, b = 4, c = 5, n = 0
• Solution:
• n = ((a--) + (b * (++c)))
– Decrementing a
– Incrementing c
– Multiplication
– Addition
n = 27
Suppose a = 3, b = 4, c = 5, n = 0
• Solution:
• n = (a++) + (b / (--c))
– Incrementing a
– Decrementing c
– Dividing b and c
– Addition
• n=4
Suppose a = 3, b = 4, c = 5, n = 0
• Solution:
• n = (a + (b * (--c))) > (c/a)
– Decrementing c
– Multiplication of b * c
– Division c/a
– Addition
– Greater than
• n=1
Assignment 1
C= 5/9 (F-32)
Assignment Answer
Assignment 1
• int sum = x + y;
• Console.WriteLine("The SUmmation of {0} and {1} = {2}",x,y,result);
• int sub = x - y;
• Console.WriteLine(sub);
• //int x = 5;
• //int y = 2;
• //int sum = x + y;
• //Console.WriteLine("x + y = "+ sum);
• //int sub = x - y;
• //Console.WriteLine("x - y = "+sub);
• //int mul = x * y;
• //Console.WriteLine("x * y ="+ mul);
• //int mod = x % y;
• //Console.WriteLine("x % y = "+ mod);
• //Console.WriteLine((++x)+y+x+y);
• //____________________________________________________________________________________________________________
•
• //int x = 10;
• //int y = 2;
• //bool z = false;