Showing posts with label IO. Show all posts
Showing posts with label IO. Show all posts

Input a double

using System;
class Program
{
    public static void Main(String[] args)
    {
        string a, b;
        double x, y;
        a = Console.ReadLine();
        b = Console.ReadLine();
        x = double.Parse(a);
        y = double.Parse(b);
        double res = x + y;
        Console.WriteLine("The Addition is: " + res);
        Console.ReadKey();
    }
}

Input an integer

using System;
class Program
{
    public static void Main(String[] args)
    {
        int x,y;
        string a,b;
        Console.WriteLine("Enter the first Number:");
        a = Console.ReadLine();
        Console.WriteLine("Enter the second Number:");
        b = Console.ReadLine();
        x = int.Parse(a);
        y = int.Parse(b);
        int res = x+y;
        Console.WriteLine("The addition is: " + res);
        Console.ReadKey();
    }
}

Reading sentence from user

using System;
class Program
{
    public static void Main(String[] args)
    {
        Console.WriteLine("Please Enter your name");
        string str = Console.ReadLine();
        Console.WriteLine("Hello " + str);
    }
}

Reading Character as a input

using System;
class Program
{
    public static void Main(String[] args)
    {
        char ch;
        ch = (char) Console.Read(); //Reading a character
        Console.WriteLine(ch);
    }
}