using System.Globalization;
using System.Net.NetworkInformation;
using System.Text;
class Progarm
{
static void Main()
{
// Greet();
// See https://aka.ms/new-console-template for more information
// 1. Hello World
Console.WriteLine("Hello, World!");
// Shortcuts Ctrl+. | Ctrl+r,r | cw \t\t | Ctrl+k,d | Ctrl+k,c | Ctrl+k,u
// 2. Primitive data types, variables, literals
byte myByte1 = 1;
byte myByte2 = 7;
sbyte mySByte1 = -1;
Console.WriteLine(myByte1 + myByte2);
// I. Types have: name (e.g. int), size, default value
// II. Variables have: name (A-Za-z_0-9 all utf-8, can't start with 0-9, can't be a keyword), type, value
// built-in types:
//2.1. integer (default = 0)
byte myByte = 23; // unsigned 8-bis (0 to 255) default = 0
sbyte mySByte = -128; // signed 8-bit (-128 to 127) default = 0
short myShort = -1000; // signed 16-bit (-32,768 to 32,767) default = 0
ushort myUshort = 2000; // unsigned 16-bit (0 to 65,535) default = 0
int myVar = 4; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
int myVar2 = 5; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
uint myUint = 12000U; // unsigned 32-bit (0 to 4, 294, 967, 295)
int sum = myVar + myVar2; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
sum = 0xA8F1; // hexadecimal literal
sum = 0XA8F1; // hexadecimal literal
// Greet();
long myLong = 42432L;// signed 64-bit (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
ulong myUlong = 23423423U; // unsigned 64-bit (0 to 18,446,744,073,709,551,615)
ulong maxIntValue = UInt64.MaxValue;
Console.WriteLine(maxIntValue); // 18446744073709551615
// 2.2. Real (default 0.0 for F/f D/d M/m)
float myFloat = 4.566F; // signed 32-bit (±1.5e-45 to ±3.4e38) up to 7 symbols/digits
myFloat = 67.8E35f; // litteral with "E/e"
double myDouble = 34.56d; // signed 64-bit (±5.0e-324 to ±1.7e+308) up to 15-16 symbols/digits
myDouble = -3.4e-10;
decimal myDecimal = 23.45M; // signed 128-bit (±1.0e-28 to ±7.9e28) precission 28-29 symbols/digits, closest to 0 ±1.0e-28, decimal floating-point arithmetic
// Declare some variables
float floatPI = 3.141592653589793238f;
double doublePI = 3.141592653589793238;
decimal decimalPI = 3.14159265358979323846m;
Console.WriteLine("Float PI is: " + floatPI); // Float PI is: 3.141593 only 7 digits
Console.WriteLine("Double PI is: " + doublePI); // Double PI is: 3.14159265358979 16 digits
Console.WriteLine(decimalPI); // 3.14159265358979323846
// 2.3. Char
char myFirstLetter = 'S';
Console.WriteLine((int)myFirstLetter);
char symbol = (char)78;
Console.WriteLine(symbol);
char myChar = '\u0065';
Console.WriteLine(myChar);
myChar = '\uffff';
Console.WriteLine(myChar);
myChar = '\'';
// escaping
char myEscape = '\n'; // \n \t \r \' \\ \" \uXXXX
// 2.4. String (default null) Reference, value in the heap. String.Compare(string1, string2) > 0 if they have to switch
string myName = "Stoyan Cheresharov";
// 2.5. Bool (default false)
bool myBool = true; // false | true
Object myObject = 2;
myObject = "Stoyan";
// 3.
int a = 5;
int b = 4;
Console.WriteLine(a + b); // 9
Console.WriteLine(a + b++); // 9
Console.WriteLine(a + b); // 10
Console.WriteLine(a + (++b)); // 11
Console.WriteLine(a + b); // 11
Console.WriteLine(14 / a); // 2
Console.WriteLine(14 % a); // 4
// 3.1. Arithmetic operators
a = 11;
b = 2;
// Arithmetic operators
Console.WriteLine(a + b);
Console.WriteLine(a - b);
Console.WriteLine(a / b);
Console.WriteLine(a * b);
Console.WriteLine(a++);
Console.WriteLine(a);
Console.WriteLine(++a);
Console.WriteLine(a % b);
Console.WriteLine(--a);
Console.WriteLine(a--);
//3.2. For comparison
Console.WriteLine(a > b);
Console.WriteLine(a < b);
Console.WriteLine(a >= b);
Console.WriteLine(a <= b);
Console.WriteLine(a == b);
Console.WriteLine(a != b);
//3.3. Logical
bool x = true;
bool y = false;
Console.WriteLine(x && y);
Console.WriteLine(x || y);
Console.WriteLine(x ^ y);
Console.WriteLine(!x);
//&&
//x y z
//0 0 0
//1 0 0
//0 1 0
//1 1 1
// ||
//x y z
//0 0 0
//1 0 1
//0 1 1
//1 1 1
// ^
//x y z
//0 0 0
//1 0 1
//0 1 1
//1 1 0
// !
//x z
//0 1
//1 0
////3.4. for asignments
//a += 3; // a = a + 3;
////3.5. Bitwise operators
//Console.WriteLine(1 << 1);
//Console.WriteLine(2 >> 1);
//Console.WriteLine(1 | 2);
//Console.WriteLine(1 & 2);
//Console.WriteLine(1 ^ 3);// 2
//// 3.6. trinary
//int c = (a > b) ? a : b;
//if (a > b)
//{
// c = a;
//}
//else
//{
// c = b;
//}
////int? a1 = null;
////int? b1 = 6;
//// a1 = null;
////int? z = a1 ?? b1;
/*
// 4. Console
Console.OutputEncoding = Encoding.UTF8;
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
Console.Write("Stoyan ");
Console.Write("Cheresharov");
Console.WriteLine("My name is Desi. I am {0} years old. my favorite number is {1}", 10, 3);
Console.WriteLine("{0,10:C2} I will continue", 1234);
// Formatting Numbers
// Standard Formatting Symbols C, D, E, F, N, P, X
Console.WriteLine("{0:C2}", 123.456); //Output: 123,46 лв.
Console.WriteLine("{0:D6}", -1234); //Output: -001234
Console.WriteLine("{0:E2}", 123); //Output: 1,23Е+002
Console.WriteLine("{0:F2}", -123.456); //Output: -123,46
Console.WriteLine("{0:N2}", 1234567.8); //Output: 1 234 567,80
Console.WriteLine("{0:P}", 0.456); //Output: 45,60 %
Console.WriteLine("{0:X}", 254); //Output: FE
// Custom Formatting Symbols 0000, ###, %, E0 Е+0 Е-0
Console.WriteLine("{0:0.00}", 1); //Output: 1,00
Console.WriteLine("{0:#.##}", 0.234); //Output: ,23
Console.WriteLine("{0:#####}", 12345.67); //Output: 12346
Console.WriteLine("{0:(0#) ### ## ##}", 29342525); //Output: (02) 934 25 25
Console.WriteLine("{0:%##}", 0.234);//Output: %23
//Console.ForegroundColor = ConsoleColor.DarkYellow;
//Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.Clear();
// Standard Formatting Symbols for DateTime
DateTime d = DateTime.Now;
Console.WriteLine("{0:d}", d); // d D
//Console.SetCursorPosition(5, 10); // left top
Console.WriteLine("Това е кирилица: ☺");
// char unicorn = '\u1F984'; ???
Console.Write("Please enter your age: ");
int age = int.Parse(Console.ReadLine());
string name = "Stoyan";
char firstLetter = name[0];
int number = 312321;
string numberString = number.ToString();
Console.WriteLine(numberString[1]);
// 5. Conditional Logic
int secondNumber = 3;
int firstNumber = 2;
if (secondNumber > firstNumber)
{
Console.WriteLine("secondNumber > firstNumber");
}
if (true)
{
Console.WriteLine("secondNumber > firstNumber");
}
else
{
Console.WriteLine("secondNumber > firstNumber");
}
int myAge = 12;
if (myAge < 3)
{
Console.WriteLine("You are a baby!");
}
else if (3 <= myAge && myAge < 12)
{
Console.WriteLine("You are a kid!");
}
else if (12 <= myAge && myAge < 18)
{
Console.WriteLine("You are a teenager!");
}
else if (18 <= myAge && myAge < 30)
{
Console.WriteLine("You are in your golden age!");
}
else
{
Console.WriteLine("You are an adult");
}
char firtsLetter = 'S';
switch (firtsLetter)
{
case 'A':
case 'S':
Console.WriteLine("Your first letter tells me you are a lucky man!");
break;
case 'V':
Console.WriteLine("You are victorious!");
break;
default:
Console.WriteLine("I don't know?");
break;
}
// 6. loops
int i = 0;
while (i < 100)
{
Console.WriteLine(i);
i++;
}
int number1 = 0;
do
{
Console.Write("Please, enter a number between 0 and 10:");
number1 = int.Parse(Console.ReadLine());
} while (number1 < 0 || number1 > 10);
for (i = 0; i < 100; i++)
{
Console.WriteLine(i);
}
int[] myArray = { 1, 2, 3,};
foreach (var item in myArray)
{
Console.WriteLine(item);
}
Console.Write("Please, enter a character: ");
int myChar1 = Console.Read();
Console.WriteLine(myChar1);
// int lucky = 1235;
int a1, a2, a3, a4;
for (int lucky = 0; lucky <= 9999; lucky++)
{
a1 = lucky / 1000;
a2 = (lucky / 100) % 10;
a3 = (lucky / 10) % 10;
a4 = lucky % 10;
if (a1 + a2 == a3 + a4)
{
Console.WriteLine(lucky);
}
}
*/
Console.Clear();
// 7.
int[] ints = { 212, 22, 3, 4 };
ints[0] = 34;
Console.WriteLine(ints[0]);
// 7.1.
int[] ints1 = new int[3];
ints1[1] = 4;
// 7.2.
int[] ints2 = new int[3] { 32, 45, 67 };
int lastElement = ints2[ints2.Length - 1];
for (int i = 0; i < ints2.Length; i++)
{
Console.WriteLine(ints2[i]);
}
int[,] matrix =
{
{32, 34, 45 },
{ 56, 54, 34},
{ 543, 34, 43}
};
int[][] jagged = {
new int[] { 32, 45, 67},
new int[] {6456, 5435, 54345, 545}
};
Console.WriteLine(jagged[1][1]);
List<int> myList = new List<int>();
myList.Add(23);
Dictionary<string, string> myDictionary = new Dictionary<string, string>();
myDictionary.Add("щастлив", "happy");
Console.WriteLine(myDictionary["щастлив"]);
var tugay = "String";
// var myInput = int.Parse(Console.ReadLine());
foreach (var item in myList)
{
Console.WriteLine(item);
}
string[] places = { "София", "пловдив" };
int counter = 0;
for (int i = 0; i < places.Length; i++)
{
if (char.IsUpper(places[i][0]))
{
Console.WriteLine(places[i]);
counter++;
}
}
Console.WriteLine("The cities with capital Letter are {0}", counter);
Console.WriteLine("2093 to BIN {0}.", Convert.ToString(2093, 2));
Console.WriteLine("2093 to OCT {0}.", Convert.ToString(2093, 8));
Console.WriteLine("2093 to HEX {0}.", Convert.ToString(2093, 16));
Console.WriteLine("2093 In a number system with base/radix = 5 {0}.",
Convert.ToString(2093, 2));
Console.WriteLine();
for (int i = ints2.Length - 1; i >= 0; i--)
{
Console.WriteLine(ints2[i]);
}
// 9. Methods
Greet(null, 1,2,23);
//Greet(ages: 1, 23, 4, name : "Viktor" );
int[] myArray = { 1231, 432432, 4234 };
Console.WriteLine(GetAverage(myArray));
Console.WriteLine(FactorialIter(10));
// 0! = 1
// n! = (n-1)! * n
// 3! = 1 * 2 * 3 = 6
Console.WriteLine(FactorialRecur(10));
//
String[] students = new String[3];
// zad 371
// a
InputStudentsNames(students);
// b
OutputStudents(students);
// c
String[] femailNames = GetFemaleNames(students);
OutputStudents(femailNames);
//double calc = 0;
//for (int x = 0; x < 169; x++)
//{
// for (int y = 0; y < 256; y++)
// {
// calc = Math.Pow(x, 2) / 169 + Math.Pow(y, 2) / 256;
// if (calc < 1)
// {
// Console.WriteLine($"The point with coordinates x = {x} y = {y} is inside the elipse");
// }
// }
//}
//Console.WriteLine(DateTime.Now);
//int x1 = 0, y1 = 0;
//while (true)
//{
// Console.Clear();
// Console.SetCursorPosition(x1, y1);
// Console.WriteLine(DateTime.Now);
// Thread.Sleep(10);
// x1++;
// y1++;
//}
// 8.
// IV
//VI
//44(10)
//4 * 10 ^ 1 + 4 * 10 ^ 0 = 40 + 4
//44(8)
//4 * 8 ^ 1 + 4 * 8 ^ 0 = 32 + 4 = 36
//44(5)
//4 * 5 ^ 1 + 4 * 5 ^ 0 = 20 + 4 = 24
//44
//44 : 2 = 22 | 0
//22 : 2 = 11 | 0
//11 : 2 = 5 | 1
//5 : 2 = 2 | 1
//2 : 2 = 1 | 0
// 1
//101100(2) = 44(10)
//0010 1100
//2C
//8421
//101 100
//5 4
//54()
//23.45
//23 : 2 = 11 | 1
//11 : 2 = 5 | 1
//5 : 2 = 2 | 1
//2 : 2 = 1 | 0
// 1
//10111.011
//1.0111011 * 2 ^ 4
//.45 * 2 = 0.9 | 0
//0.9 * 2 = 0.8 | 1
//0.8 * 2 = 0.6 | 1
//123.56 => 1,23.56 * 10 ^ 2
//number = 346
//(r ^ n - 1) - number
//(10 ^ 3 - 1) - 346 =
//999
//-
//346
//---- -
//653
//9999999999
//-
//4332423532
//----------------
//5667...
//1111111111111
//-
//1010101111111
//------------------
//0101010000000
//(r ^ n - 1) - number
//(r ^ n) - number
//7 - 3 = 4
//7 + 7 = 1 | 4
/*
// ------ in a nutshell -----
//a += 3; // a = a + 3;
//// essentials
//// 4.
//Console.WriteLine();
//string name = Console.ReadLine();
//double n = double.Parse(Console.ReadLine());
//// 5. Conditional logic
//// 5.1.
//if (a > 5)
//{
// Console.WriteLine("a > 5");
//}
//if (a > 5)
//{
// Console.WriteLine("a > 5");
//}
//else
//{
// Console.WriteLine("a < 5");
//}
//Console.WriteLine("Please enter your age: ");
//int age = int.Parse(Console.ReadLine());
//if (age > 0 && age <= 3)
//{
// Console.WriteLine("You are a baby");
//}
//else if (age > 3 && age <= 12)
//{
// Console.WriteLine("You are a kid");
//}
//else if (age > 12 && age <= 18)
//{
// Console.WriteLine("You are a teenager");
//}
//else
//{
// Console.WriteLine("You are an adult");
//}
//char firstLetter = Char.Parse(Console.ReadLine());
//switch (firstLetter)
//{
// case 'A':
// case 'N':
// Console.WriteLine("Maybe your name is Nilyay");
// break;
// default:
// Console.WriteLine("I don't know");
// break;
//}
//// 6. Loops
//int i = 0;
//while (i < 100)
//{
// Console.WriteLine(i);
// i++;
//}
//do
//{
// Console.WriteLine("Please enter your age: ");
// age = int.Parse(Console.ReadLine());
//} while (age < 0 && age > 120);
//for (i = 0; i < 100; i++)
//{
// Console.WriteLine(i);
//}
Greet("Nilyay");
int[] ages = new int[10];
ages[0] = 18;
ages[5] = 17;
foreach (int item in ages)
{
Console.WriteLine(item);
}
Greet("Magi");
int number = 5698;
int a1 = number / 1000;
int a2 = (number / 100) % 10;
int a3 = (number / 10) % 10;
int a4 = number % 10;
Console.WriteLine("The number in reverse is {0}{1}{2}{3}", a4, a3, a2, a1);
}
static void Greet(string name = "Megan")
{
Console.WriteLine("Hello" + name);
}
static int CalculateSum(int a, int b)
{
return a + b;
}
*/
}
static void Greet(String name = "Viktor", params int[] ages)
{
Console.WriteLine($"Hello {name}");
foreach (var item in ages)
{
Console.WriteLine(item);
}
}
static double GetAverage(int[] n)
{
double average = 0;
int sum = 0;
foreach (var item in n)
{
sum += item;
}
if (n.Length != 0) average = sum / n.Length;
return average;
}
static int FactorialIter(int n)
{
int mul = 1;
for (int i = 1; i <= n; i++)
{
mul *= i;
}
return mul;
}
// 0! = 1
// n! = (n-1)! * n
static int FactorialRecur(int n)
{
if (n == 0) return 1;
return FactorialRecur(n - 1) * n;
}
static void InputStudentsNames(String[] names)
{
for (int i = 0; i < names.Length; i++)
{
Console.Write("Please, enter the name (first, middle, family) of {0}:", i);
names[i] = Console.ReadLine();
}
}
static void OutputStudents(String[] students)
{
for (int i = 0; i < students.Length; i++)
{
Console.WriteLine("Student number {0} = {1}", i, students[i]);
}
}
static String[] GetFemaleNames(String[] students)
{
String[] femaleNames = new String[students.Length];
int counter = 0;
for (int i = 0; i < students.Length; i++)
{
if (students[i][students.Length - 1] == 'а')
{
femaleNames[counter] = students[i];
counter++;
}
}
return femaleNames;
}
}
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎