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
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Write("MyFabulousName");
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

Task2: "Echolalia" Read a line from the console and then return the same string back onto the console.

using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
Console.Write(str + "\n");
Console.Write(str + "\n");
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

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"
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)
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

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 π
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);
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

Task5: Write a program that computes the BMI of a person when his/her body weight and height are to be given

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);
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

コメント

このブログの人気の投稿

C# Tutorial Footage No.2 [Conversion of Values]