C# Questions Answers-C# operators (PartII)


C# operators (PartII)

1. What is the output of the following C# program?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
  class Program
  {

    static void Main(string[] args)
    {
      int x = 10, y = 15;
      int mul = x * y;
      Console.WriteLine("{0}*{1}={2}",x,y,mul);
      Console.ReadLine();

   }

  }
}
Check answer 2. What is the output of the following C# program?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
  class Program
   {

    static void Main(string[] args)
    {
     float in_m, foot, yard, cent, meter;
     Console.Write("Enter a measurement in inches:");
     in_m=float.Parse(Console.ReadLine());
     foot = 12 * in_m;//1 foot=12 inches
     yard = 36 * in_m;//1 yard=36 inches
     cent = in_m / 2.54f;//1 inch=2.54 centimeters
     meter = 39.37f * in_m;//1 meter=39.37 inches

    Console.WriteLine("{0,-15}{1,-15}{2,-30}{3,-15}", foot+"feet", yard+"yards", cent+"centimeters", meter+"meters");

    Console.ReadLine();

   }

  }
}
  getch();
  return 0;
}
 

Check answer 3. What is the output of the following C# program?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
  class Program
  {

    static void Main(string[] args)
    {
      int x;
      int f, m, l;
      Console.Write("Enter 3 digit-integer number:");
      x=Int32.Parse(Console.ReadLine()) ;
      f = x / 100;
      l = x % 10;
      m = (x / 10) % 10;

      Console.WriteLine("{0}\t{1}\t{2}", f, m, l);
      Console.WriteLine("{0}\t{1}",m, l);
      Console.WriteLine("{0}",l);

      Console.ReadLine();

        }

    }
}

Check answer


Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.