What will be the output of the following C# code? [code] static void Main(string[] args) { float s = 0.1f; while (s <= 0.5f)

Quang Hiếu

New member
What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     float s = 0.1f;
     while (s <= 0.5f)
     {
         ++s;
         Console.WriteLine(s);
     }
     Console.ReadLine();
 }
A. 0.1
B.
Code:
 1.1
C. 0.1 0.2 0.3 0.4 0.5
D. No output
 
Answer: b
Explanation: For the first while condition check when s = 0. If it is true as control goes inside loop ++s increments value of s by 1 as 1+0.1 =
Code:
 1.1
. So, for next condition while loop fails and hence, prints final value of s as
Code:
 1.1
.
Output:
Code:
 1.1
 

Tìm kiếm

Back
Top