2. Create, compile and run a “Hello C#” console application.
using System; class HelloCSharp { static void Main() { Console.WriteLine("Hello C#"); } }
3. Modify the application to print your name.
using System; class PrintMyName { static void Main() { Console.WriteLine("Kaloyan"); } }
4. Write a program to print the numbers 1, 101 and 1001.
using System; class PrintNumbers { static void Main() { Console.WriteLine(1); Console.WriteLine(101); Console.WriteLine(1001); } }6. Create console application that prints your first and last name.
using System; class PrintMyNameAndSurname { static void Main() { Console.WriteLine("Kaloyan Savov"); } }
7. Create a console application that prints the current date and time.
using System; class PrintCurrentDateAndTime { static void Main() { DateTime now = DateTime.Now; Console.WriteLine(now) } }
8. Create a console application that calculates and prints the square of the number 12345.
using System; class CalculateSquare { static void Main() { Console.WriteLine(12345*12345); } }
9. Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, ...
using System; class PrintFirstTenNumbers { static void Main() { int plus = 2; int minus = -3; Console.Write(plus + ", " + minus); for (int i = 0; i < 4; i++) { plus += 2; minus -= 2; Console.Write(", " + plus + ", " + minus); } Console.WriteLine(); } }
12.* Write a program to read your age from the console and print how old you will be after 10 years.
using System; class PrintMyAgeAfterTenYears { static void Main() { Console.WriteLine("Please enter your age (1 to 130 Years)"); int age = int.Parse(Console.ReadLine()); int result = age + 10; if (age > 130) { Console.WriteLine("You are too old. Try again. ;)"); } if (age < 1) { Console.WriteLine("Wrong age. Try again."); } else { Console.WriteLine("Your age after 10 years will be: " + result + " years"); } } }
Няма коментари:
Публикуване на коментар