My Report

C# Programming Practice Test 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     float s = 0.1f;
     while (s <= 0.5f)
     {
         ++s;
         Console.WriteLine(s);
     }
     Console.ReadLine();
 }

2. What will be the output of the following C# code?

static void Main(string[] args)
{
    int x = 10;
    do
    {
        Console.WriteLine( x++);
    }
    while(Convert.ToBoolean(5) && Convert.ToBoolean(4) && Convert.ToBoolean(3) 
    && Convert.ToBoolean(2) && Convert.ToBoolean(1) && Convert.ToBoolean(0));    
    Console.ReadLine();
}

3. What will be the output of the following C# code?

  static void Main(string[] args)
  {  
      int a = 5;
      if (Convert.ToBoolean((.002f) -(0.1f)))
      Console.WriteLine("Sachin Tendulkar");
      else if (a == 5)
      Console.WriteLine("Rahul Dravid");
      else
      Console.WriteLine("Ms Dhoni");
      Console.ReadLine();
  }
  

4. Which of the following conditions are true in the following C# code?

 static void Main(string[] args)
 {
     Console.WriteLine("Enter a letter:");
     char c = (char)Console.Read();
     if (Char.IsDigit(c) == true)
         Console.WriteLine("A number");
     else if (char.IsLower(c) == true)
         Console.WriteLine("A lowercase letter");
     else if (char.IsUpper(c) == true)
         Console.WriteLine("An uppercase letter");
     Console.ReadLine();
 }
 a. Enter a letter :
    a
    An uppercase letter
 b. Enter a letter :
    A
    An uppercase letter
 c. Enter a letter :
    2
    A number
 d. Enter a letter :
    2
    A lowercase letter.
 

5. What will be the output of the following C# code?

  static void Main(string[] args)
  {
      int a = 5, b = 10;
      if (Convert.ToBoolean(Convert.ToInt32(0xB)))
      if (Convert.ToBoolean(Convert.ToInt32(022)))
      if (Convert.ToBoolean(Convert.ToInt32('\xeb')))
      Console.WriteLine("java");
      else ;
      else ;
      else ;
  }

6. What will be the output of the following C# code?

 
   static void Main(string[] args)
   {
       int i;
       for (i =-3; i <= 3; i++)
       {
           switch (i)
           {
           case 0:
               Console.WriteLine("zero");
               break;
           }
           if (i > 0)
               Console.WriteLine("A");
           else if (i < 0)
               Console.WriteLine("B");
       }
       Console.ReadLine();
   }
  

7. What will be the output of the following C# code?

static void Main(string[] args)
{
    int x = 0;
    do
    {
        x++;
        if (x == 5)
        {
            x++;
            continue;
            break;
        }
        Console.WriteLine(x + " ");
    }
}while (x < 10);

8. What will be the output of the following C# code?

 
 static void Main(string[] args)
 {
     int I, X;
     for (I = 1; I <= (9 % 2 + I); I++)
     {
         X = (I * 3 + I * 2) / I;
         Console.WriteLine(X);
     }
     Console.ReadLine();
 }

9. What will be the output of the following C# code?

   static void Main(string[] args)
   {
       int i = 1;
       while (i <= 1)
       {
           if ('A' < 'a')
           {
               Console.WriteLine("Hello...");
           }
           else
           {
              Console.WriteLine("Hi...");
           }
              i++;
       }
       Console.ReadLine();
   }
    

10. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     long  x;
     x = Convert.ToInt32(Console.ReadLine());
     do
     {
         Console.WriteLine(x % 10);
     }while ((x = x / 10) != 0);
     Console.ReadLine();
 }
 enter x = 1234.

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.