Find the output of C#.Net programs | Arrays | Set 3: Enhance the knowledge of C#.Net Arrays concepts by solving and finding the output of some C#.Net programs.
Question 1:
using System;
namespace Demo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
float[] ARR = { 10.2, 11.5, 22.6 };
foreach (float X in ARR)
{
Console.WriteLine(X % 5);
}
}
}
}
Question 2:
using System;
namespace Demo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
float[] ARR = { 13.6F, 11.5F, 22.6F };
float R = 0.0F;
foreach (float X in ARR)
{
R = X%5;
Console.WriteLine(R);
}
}
}
}
Question 3:
using System;
namespace Demo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
float[] ARR1 = { 13.6F, 11.5F, 22.6F };
float[] ARR2;
ARR2 = ARR1;
float R = 0.0F;
foreach (float X in ARR2)
{
R = X % 5;
Console.WriteLine(R);
}
}
}
}
Question 4:
using System;
namespace Demo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
float[] ARR1 = { 13.6F, 11.5F, 22.6F };
float[] ARR2;
ARR2 = ARR1;
ARR2[1] = 20.5F;
foreach (float X in ARR1)
{
Console.WriteLine(X);
}
}
}
}
Question 5:
using System;
namespace Demo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
string[] str = { 'Hello', 'Hii', 'Bye' };
foreach (string X in str)
{
Console.WriteLine(X);
}
}
}
}
Answer 1:
Output:
Explanation:
The above program will generate syntax errors because, in the above float array, we assigned with double values. Here, we need to use 'F' suffix to initialized float values. The correct way is given below,
float[] ARR = { 10.2F, 11.5F, 22.6F };
Answer 2:
Output:
Explanation:
In the above program, we created an array of float values ARR, and we created one more float variable 'R'.
foreach (float X in ARR) { R = X%5; Console.WriteLine(R); }
Here, we accessed each element of an array using the foreach loop and find the remainder then print the remainder on the console screen.
Answer 3:
Output:
Explanation:
In the above program, we created an array of float values ARR1, and we created one more float variable R, Initialized with "0.0F". Here, we assigned the address of ARR2 to the ARR1.
foreach (float X in ARR2) { R = X%5; Console.WriteLine(R); }
Here, we accessed each element of the array using foreach loop and find remainder then print the Remainder on the console screen.
Answer 4:
Output:
Explanation:
In the above program, we created an array of float values ARR1, and we assigned the address of ARR2 to the ARR1. It means we made the change in anyone that will reflect in another array also because both are pointing to the same array internally.
Here, we assigned value 20.5F in the 1st position of ARR2, but it will also reflect in ARR1. So here we accessed each element of array ARR1 one by one using foreach loop, and print them on the console screen.
Answer 5:
Output:
Explanation:
The above program will generate syntax errors because we enclosed the string within single quotes instead of double-quotes. Single quotes are used for a single character, not for the strings in C#.
need an explanation for this answer? contact us directly to get an explanation for this answer