My Report

C# Loops 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 i = 0;
     while (i <= 50)
     {
         if (i % 10 == 0)
         continue;
         else
         break;
         i += 10;
         Console.WriteLine(i % 10);
    }
}

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

 static void Main(string[] args)
 {
     int x = 0;  
     while (x < 20)
     {
         while (x < 10)
         {
             if (x % 2 == 0)
             {
                 Console.WriteLine(x);
             }
             x++;
         }
     }
     Console.ReadLine();
 }

4. Correct syntax for while statement is:

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

 static void Main(string[] args)
 {
     int x;
     x = Convert.ToInt32(Console.ReadLine());
     int c = 1;
     while (c <= x)
     {
         if (c % 2 == 0)
         {
             Console.WriteLine("Execute While " + c + "\t" + "time");
         }
         c++;
     }
     Console.ReadLine();
 }
for x = 8.

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

  static void Main(string[] args)
  {
      int i = 1, j = 1;
      while (++i <= 10)
      {
          j++;
      }
      Console.WriteLine(i+ "  " +j);
      Console.ReadLine();
  }
 

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

  static void Main(string[] args)
  {
      float i = 1.0f,  j = 0.05f;
      while (i  < 2.0f  &&  j  <= 2.0f)
      {
          Console.WriteLine(i++ - ++j);
      }
      Console.ReadLine();
  }

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

 
  static void Main(string[] args)
  {
      int i = 0;
      while (i++ != 0) ;
      Console.WriteLine(i);
      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)
 {
     int i, j;
     for (i = 1; i <= 3; i++)
     {
         j = 1;
         while (i % j == 2)
         {
             j++;
         }
         Console.WriteLine(i + " " + j);
     }
     Console.ReadLine();
 }

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

  static void Main(string[] args)
  {
      int n, r;
      n = Convert.ToInt32(Console.ReadLine());
      while (n > 0)
      {
          r = n % 10;
          n = n / 10;
          Console.WriteLine(+r);
      }
      Console.ReadLine();
  }
 for n = 5432.

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

 static void Main(string[] args)
 {
     int i;
     i = 0;
     while (i++ < 5)
     {
         Console.WriteLine(i);
     }
     Console.WriteLine("\n");
     i = 0;
     while ( ++i < 5)
    {
        Console.WriteLine(i);
    }
    Console.ReadLine();
}
 

 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

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.