Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Problem 1. Play with Visual Studio
- * Familiarize yourself with Microsoft Visual Studio (if you already have it installed) or install Visual Studio
- * (or Visual Studio Express) at your laptop or home computer. Search in Internet for the correct download
- * link: http://google.com/search?q=download+visual+studio.
- * Start Visual Studio and play with it. Create a simple C# program (console application), compile and run it.
- */
- using System;
- public class PrintWindows
- {
- public static void Main()
- {
- Console.WriteLine("Windows");
- }
- }
- /* Problem 4. Hello World
- * Create, compile and run a “Hello C#” console application. Ensure you have named the application well (e.g. “”HelloCSharp”).
- */
- using System;
- public class HelloCSharp
- {
- public static void Main()
- {
- Console.WriteLine("HelloCSharp");
- }
- }
- /* Problem 5. Print Your Name
- * Modify the previous application to print your name. Ensure you have named the application well (e.g. “PrintMyName”).
- */
- using System;
- public class PrintMyName
- {
- public static void Main()
- {
- Console.WriteLine("Pesho");
- }
- }
- /* Problem 6. Print Numbers
- * Write a program to print the numbers 1, 101 and 1001, each at a separate line.
- */
- using System;
- public class PrintNumbers
- {
- public static void Main()
- {
- Console.WriteLine(1);
- Console.WriteLine(101);
- Console.WriteLine(1001);
- }
- }
- /* Problem 7. Print First and Last Name
- * Create console application that prints your first and last name, each at a separate line.
- */
- using System;
- public class PrintMyName
- {
- public static void Main()
- {
- Console.WriteLine("Petar");
- Console.WriteLine("Tseperski");
- }
- }
- /* Problem 8. Square Root
- * Create a console application that calculates and prints the square root of the number 12345.
- * Find in Internet “how to calculate square root in C#”.
- */
- using System;
- public class CalcSqureRoot
- {
- public static void Main()
- {
- Console.WriteLine(Math.Sqrt(12345));
- }
- }
- /* Problem 9. Print a Sequence
- * Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, ...
- */
- using System;
- public class PrintSequence
- {
- public static void Main()
- {
- for (int i = 2; i < 12; i++)
- {
- if (i % 2 == 0)
- {
- Console.Write(i);
- }
- else
- {
- Console.Write(-i);
- }
- if (i != 11)
- {
- Console.Write(", ");
- }
- }
- Console.WriteLine();
- }
- }
- /* Problem 10. Reformat C# Code
- * Reformat the following C# code to make it readable according to the C# best practices for code formatting.
- * Change the casing of the identifiers in the code (e.g. use PascalCase for the class name):
- using
- System;
- class hoRRiblEcoDe
- {
- static
- void
- Main()
- {
- Console.
- WriteLine("Hi, I am horribly formatted program"
- ); Console.
- WriteLine("Numbers and squares:")
- ; for (int i = 0;
- i < 10;
- i++)
- {
- Console.WriteLine(i +
- " --> " + i
- *
- i);
- }
- }
- }
- */
- using System;
- public class HorribleCode
- {
- public static void Main()
- {
- Console.WriteLine("Hi, I am horribly formatted program");
- Console.WriteLine("Numbers and squares:");
- for (int i = 0; i < 10; i++)
- {
- Console.WriteLine(i + " --> " + i * i);
- }
- }
- }
- /* Problem 14. * Current Date and Time
- * Create a console application that prints the current date and time. Find in Internet how.
- */
- using System;
- public class PrintCurrentDateTime
- {
- public static void Main()
- {
- Console.WriteLine(DateTime.Now);
- }
- }
- /*
- * Problem 15. * 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;
- public class PrintFutureAge
- {
- public static void Main()
- {
- Console.Write("Input your age: ");
- string input = Console.ReadLine();
- int age = int.Parse(input);
- int result = age + 10;
- Console.WriteLine("Your age after 10 years will be: {0}", result);
- }
- }
- /* Problem 16. * Print Long Sequence
- * Write a program that prints the first 1000 members of the sequence: 2, -3, 4, -5, 6, -7, …
- * You might need to learn how to use loops (search in Internet).
- */
- using System;
- public class PrintLongSequence
- {
- public static void Main()
- {
- for (int i = 2; i < 1002; i++)
- {
- if (i % 2 == 0)
- {
- Console.Write(i);
- }
- else
- {
- Console.Write(-i);
- }
- if (i != 1001)
- {
- Console.Write(", ");
- }
- }
- Console.WriteLine();
- }
- }
- /* Problem 17. * Play with the Debugger in Visual Studio
- * Write a program that prints at the console the numbers from 1 to 1000, each at a separate line.
- * You might need to learn how to use loops (search in Internet). Set a breakpoint in the line, which prints the next number
- * in the Visual Studio code editor. Run the program through the debugger using the [F5] key. When the debugger stops at the
- * breakpoint trace the code execution with [F10] key.
- */
- using System;
- public class PrintLongSequenceForDebugging
- {
- public static void Main()
- {
- for (int i = 1; i < 1001; i++)
- {
- Console.WriteLine(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment