write a Nested loop in C# to print out the following output using windows form.
0
0 1
0 2 4
0 3 6 9
0 4 8 16 32
Code
public partial class Pattern : Form
{
public Pattern()
{
InitializeComponent();
}
private void Pattern_Load(object sender, EventArgs e)
{
for(int i=0;i<5;i++)
{
string str = "0 ";
int k = i;
for (int j = 1; j <= i; j++)
{
if (i % 2 != 0)
{
str += k + " ";
k += i;
}
else
{
str += k+" ";
k *= 2;
}
}
txtNestedloop.Text= txtNestedloop.Text +str +"\r\n";
}
}
}
design
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
Get Answers For Free
Most questions answered within 1 hours.