C# Tutorial Footage No.1
Task1: Showing my fabulous name on the console
(Quick Help) IF the console shuts itself down right after your compiled code is executed, try; running your app via pressing [Ctrl + F5]. How to keep the console from shutting down when running your new Visual Studio Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Write("MyFabulousName"); | |
} | |
} | |
} |
Task2: "Echolalia" Read a line from the console and then return the same string back onto the console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string str = Console.ReadLine(); | |
Console.Write(str + "\n"); | |
Console.Write(str + "\n"); | |
} | |
} | |
} |
Task3: Write a program that computes the Reciprocal of a complex number x + iy
In this execercise you learn to parse the input into "double" type data using "Double.Parse Method"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Write("This program computes the Reciprocal of a complex number x + iy "); | |
Console.Write("Enter the real part \n"); | |
double x = double.Parse(Console.ReadLine()); | |
Console.Write("Enter the imaginary part\n"); | |
double y = double.Parse(Console.ReadLine()); | |
// computes the norm of the complex number | |
double norm = x * x + y * y; | |
// show the result on cosole | |
Console.Write("The reciprocal number of {0}+i({1})is + {2}+i({3})", x, y, x / norm, y / norm) | |
} | |
} | |
} |
Task4: Compute a circle's area from its radius given
This one was bit tricky since I needed to use "Math.Pi" as the constant number π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Write("This program computes the area of a circle with radius x "); | |
Console.Write("Enter radius(x) \n"); | |
double x = double.Parse(Console.ReadLine()); | |
// computes the norm of the complex number | |
double area = Math.PI * x * x; | |
// show the result on cosole | |
Console.Write("The area of the circle with radius {0} is {1}", x, area); | |
} | |
} |
Task5: Write a program that computes the BMI of a person when his/her body weight and height are to be given
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Write("This program computes the BMI from a set of body weight and height"); | |
Console.Write("Enter your body weight in kilograms \n"); | |
double weight = double.Parse(Console.ReadLine()); | |
Console.Write("Enter your height in centimeters \n"); | |
double height = double.Parse(Console.ReadLine()); | |
// conversion to meters | |
height *= 0.01; | |
// computes the norm of the complex number | |
double bmi = weight /(height * height); | |
// show the result on cosole | |
Console.Write("your BMI is {0}", bmi); | |
} | |
} | |
} |
コメント
コメントを投稿