What will be the output of the following C# code? [code] static void Main(string[] args) { int n = 5; int x = 4; int z,

Đạt Michio

New member
What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     int n = 5;
     int x = 4;
     int z, c, k;
     for (c = 1; c <= n; c++)
     {
         for (k = 1; k <= c; k++)
     {
         z = 3 * x * x + 2 * x + 4 / x + 8;
         Console.Write(Convert.ToString(Convert.ToChar(z)));
     }
         Console.WriteLine("\n");
     }
     Console.ReadLine();
 }
A.
A
AA
AAA
AAAA
B.
A
AB
ABC
ABCD
C.
A
AA
AAA
AAAA
AAAAA
D.
A
BC
DEF
DEFG
 
Answer: c
Explanation: Solving the expression for value of 'z'as 65. With, each passage of loop value number of 'z' increases for each row as
Code:
                           Row 1: A
                           Row 2: AA 
                                  -
                                  -
                           Row 5: AAAAA
 Output : A
          AA
          AAA
          AAAA
          AAAAA
 

Tìm kiếm

Back
Top