EXPRESSIONS Expressions evaluate int r 150 20 2
- Slides: 30
ИЗРАЗИ(EXPRESSIONS)
Изрази(Expressions) � � Изразите са поредица от оператори, литерали и променливи, които се изчисляват(evaluate) до някаква стойност Пример: int r = (150 -20) / 2 + 5; // Expression for calculation of circle area double surface = Math. PI * r; // Expression for calculation of circle perimeter double perimeter = 2 * Math. PI * r;
Принтиране на конзолата пример static void Main() { string name = "Peter"; int age = 18; string town = "Sofia"; Console. Write("{0} is {1} years old from {2}. ", name, age, town); // Result: Peter is 18 years old from Sofia. Console. Write("This is on the same line!"); Console. Write. Line("Next sentence will be" + " on a new line. "); } Console. Write. Line("Bye, bye, {0} from {1}. ", name, town);
Console. Read. Line() � � Чете един ред от символи Връща стойност от тип string Console. Write("Please enter your first name: "); string first. Name = Console. Read. Line(); Console. Write("Please enter your last name: "); string last. Name = Console. Read. Line(); Console. Write. Line("Hello, {0} {1}!", first. Name, last. Name);
УСЛОВНА ЛОГИКА(CONDITIONAL LOGIC)
If Statement - пример static void Main() { Console. Write. Line("Enter two numbers. "); int bigger. Number = int. Parse(Console. Read. Line()); int smaller. Number = int. Parse(Console. Read. Line()); if (smaller. Number > bigger. Number) { bigger. Number = smaller. Number; } } Console. Write. Line("The greater number is: {0}", bigger. Number);
if-else Statement - пример � Проверява дали дадено число е четно или нечетно string s = Console. Read. Line(); int number = int. Parse(s); if (number % 2 == 0) { Console. Write. Line("This number is even. "); } else { Console. Write. Line("This number is odd. "); }
Вложени условни стейтмъни пример if (first == second) { Console. Write. Line( "These two numbers are equal. "); } else { if (first > second) { Console. Write. Line( "The first number is bigger. "); } else { Console. Write. Line("The second is bigger. "); } }
switch-case Statement � Избира за изпълнение един от case стейтмъните в зависимост от стойността на израза в switch стейтмъна switch (day) { case 1: Console. Write. Line("Monday"); break; case 2: Console. Write. Line("Tuesday"); break; case 3: Console. Write. Line("Wednesday"); break; case 4: Console. Write. Line("Thursday"); break; case 5: Console. Write. Line("Friday"); break; case 6: Console. Write. Line("Saturday"); break; case 7: Console. Write. Line("Sunday"); break; default: Console. Write. Line("Error!"); break; }
Цикъл while - пример int counter = 0; while (counter < 10) { Console. Write. Line("Number : {0}", counter); counter++; }
do-while цикъл � Цикъл, гарантиращ поне едно изпълнение на кода в цикъла static void Main() { int n = Convert. To. Int 32(Console. Read. Line()); int factorial = 1; do { factorial *= n; n--; } while (n > 0); } Console. Write. Line("n! = {0}", factorial);
N^M – пример � Изчислява N на степен M(N^M): static void Main() { int n = int. Parse(Console. Read. Line()); int m = int. Parse(Console. Read. Line()); decimal result = 1; for (int i=0; i<m; i++) { result *= n; } Console. Write. Line("n^m = " + result); }
- Sum0
- Interface calculator public int add(int a int b) class test
- Public void drawsquare(int x, int y, int len)
- Divideint
- Int max(int x int y)
- Simplify square root of 82
- Int factorial(int n)
- Void f(int i) int j=0
- Interface myinterface int foo(int x)
- Arduino constant int
- Int argc char argv
- Int.max
- Int main(int argc, char** argv)
- Int main() int num=4
- #include stdio.h int main() int i = 5
- Void swap
- Evaluate expressions using properties of exponents
- Evaluate the expression trigonometry
- Evaluate exponential expressions
- Evaluate absolute value expressions calculator
- Arithmetic expressions containing a null value evaluate to
- Evaluating expressions with exponents
- Evaluate and simplify
- Arithmetic expressions containing a null value evaluate to
- Evaluate 32 3/5
- Evaluate property for reac inspection
- Evaluate 144/121
- Evaluate math
- Higher pe describe questions
- What sight made brian scream in horror
- Expression and equation