Advertisement
fabi0

Untitled

Oct 29th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. class My_Name
  5. {
  6.     static void Main()
  7.     {
  8.         string firstName = "Azrin";
  9.         string lastName = "Hadah";
  10.         int counter = 0;
  11.         int left = 2;
  12.         int right = -3;
  13.         int age = 0;
  14.         int older = 10;
  15.  
  16.         Console.WriteLine("Task 1 : Create, compile and run a β€œHello C#” console application.\n");
  17.         Console.ReadKey(true);
  18.  
  19.         Console.WriteLine("Task 2: Create console application that prints your first and last name.\n");
  20.         Console.WriteLine("Hello ! My name is {0} {1}\n", firstName, lastName);
  21.         Console.ReadKey(true);
  22.  
  23.         Console.WriteLine("Task 3 : Write a program to print the numbers 1, 101 and 1001.\n");
  24.         Console.WriteLine("1");
  25.         Console.WriteLine("101");
  26.         Console.WriteLine("1001");
  27.         Console.ReadKey(true);
  28.  
  29.         Console.WriteLine("Task 4 : Create a console application that prints the current date and time.\n");
  30.         DateTime time = DateTime.Now;
  31.         string format = "MMM ddd d HH:mm yyyy";
  32.         Console.WriteLine("Current date and time is :{0}", time.ToString(format));
  33.         Console.ReadKey(true);
  34.  
  35.         Console.WriteLine("Task 5 : Create a console application that calculates and prints the square of the number 12345.\n");
  36.         double square = Math.Pow(12345, 2);
  37.         Console.WriteLine("Square of 12345 is : {0}", square);
  38.         Console.ReadKey(true);
  39.  
  40.         Console.WriteLine("Task 6 : Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, ...\n");
  41.  
  42.         for (int i = 0; i < 5; i++)
  43.         {
  44.             Console.WriteLine(left);
  45.             Console.WriteLine(right);
  46.             left = left + 2;
  47.             right = right - 2;
  48.             counter++;
  49.         }
  50.         Console.ReadKey(true);
  51.  
  52.         Console.WriteLine("Task 7 : Write a program to read your age from the console and print how old you will be after 10 years.\n");
  53.  
  54.         Console.WriteLine("Type your age:");
  55.         while (true)
  56.         {
  57.             try
  58.             {
  59.                 age = int.Parse(Console.ReadLine());
  60.                 older += age;
  61.                 Console.WriteLine("Ten years later you will be : {0}", older);
  62.                 break;
  63.             }
  64.             catch (Exception ex)
  65.             {
  66.                 Console.WriteLine(ex.Message);
  67.             }
  68.         }
  69.  
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement