C# – Introduction To Programming

Условия и решения на задачите от лекция “Introduction To Programming”

Задача 2. Hello CSharp

Условие: Create, compile and run a “Hello C#” console application.

Решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _2.HelloCSharp
{
class Program
{
static void Main()
{
Console.WriteLine("Hello C#");
}
}
}

Задача 3. Print Name

Условие: Modify the application to print your name.

Решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _3.PrintName
{
class Program
{
static void Main()
{
Console.WriteLine("Petar Stoyanov Yankov");
}
}
}

Задача 4. Print Numbers

Условие: Write a program to print the numbers 1, 101 and 1001.

Решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _4.PrintNumbers
{
class Program
{
static void Main()
{
int a = 1;
int b = 101;
int c = 1001;
Console.WriteLine("{0},{1},{2}", a, b, c);
}
}
}

Задача 6. Print First And Last Name

Условие: Create console application that prints your first and last name.

Решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _6.PrintFirstAndLastName
{
class Program
{
static void Main()
{
Console.WriteLine("Petar Yankov");
}
}
}

Задача 7. Print Current Date And Time

Условие: Create a console application that prints the current date and time.

Решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _7.PrintCurrentDateAndTime
{
class Program
{
static void Main()
{
Console.WriteLine(DateTime.Now);
}
}
}

Задача 8. Print Square

Условие: Create a console application that calculates and prints the square of the number 12345.

Решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _8.PrintSquare
{
class Program
{
static void Main()
{
int n = 12345;
Console.WriteLine(n * n);
}
}
}

Задача 9. Print The First 10 Numbers

Условие: Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, …

Решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _9.PrintTheFirst10Numbers
{
class Program
{
static void Main()
{
for (int i = 2; i < 12; i++)
{
if (i % 2 == 0)
{
Console.Write("{0},", i);
}
else
{
Console.Write("{0},", -i);
}
}
Console.WriteLine();
}
}
}

Задача 12. Print Age After 10 Years

Условие: Write a program to read your age from the console and print how old you will be after 10 years.

Решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _12.PrintAgeAfter10Years
{
class Program
{
static void Main()
{
Console.Write("Enter your age:");
int Age = int.Parse(Console.ReadLine());
Console.WriteLine("Your age after 10 years will be:{0}", Age + 10);
}
}
}