Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C# code?
static void Main(string[] args)
{
float sum;
int i;
sum = 0.0F;
for (i = 1; i <= 10; i++)
{
sum = sum + 1 /(float)i;
}
Console.WriteLine(“sum =” +sum);
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
float sum;
int i;
sum = 0.0F;
for (i = 1; i <= 10; i++)
{
sum = sum + 1 /(float)i;
}
Console.WriteLine(“sum =” +sum);
Console.ReadLine();
}
a) 2.000
b) 2.910
c) 2.928
d) 3.000

Answer: c
Explanation: sum = 2.928698.

Join The Discussion