Worksheet On Nested Loops
Worksheet On Nested Loops
QUESTION 1
Indicate the output that will be displayed to the console.
int i, j;
for (i = 1; i <= 3; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write("{0}{1}", i,j);
}
Console.WriteLine();
}
QUESTION 2
Indicate the output that will be displayed to the console.
int i, j, answer=0;
Console.WriteLine();
Console.ReadLine();
int i, j;
for (i = 1; i <= 5; i++)
for (j = 1; j <= i; j++)
{
Console.Write("*");
Console.WriteLine();
}
The above code prints outs the following to the console.
QUESTION 4
int i, j;
for (i = 1; i <= 5; i++)
for (j = 1; j <= i; j++)
{
Console.Write("*");
Console.WriteLine();
}
The above code prints outs the following to the console.
Example Output:
Year: 1986
Rainfall for month 1: 0.88
Rainfall for month 2: 1.11
Average Rainfall for 1986: 0.995
Year: 1987
Rainfall for month 1: 0.76
Rainfall for month 2: 0.94
Average Rainfall for 1987: 0.850
Year: 1988
Rainfall for month 1: 0.82
Rainfall for month 2: 0.80
Average Rainfall for 1988: 0.81
dinnerPrice += 10.00;
tipRate = 0.10;
Console.WriteLine();
}
QUESTION 7
Identify and correct the EIGHT errors in this code so it works as shown.
sum = testMark;
}
average = sum / 3;
Console.WriteLine("Average: {0}");
Console.WriteLine();
}
Console.ReadLine();
}
QUESTION 9
Console.Write('*');
Console.WriteLine();
}