Answer the question
In order to leave comments, you need to log in
How to do alternation correctly?
Wasap!
There are input parameters (for example):
Start 11
End 18
Some name name
First of all, you need to get an array of numbers from 11 to 18
int start = 11, last = 18;
int[] arr = Enumerable.Range(start, last - start + 1).ToArray();
int count = arr.Count();
for (int j = 0; j < count; j++)
{
for (int i = 11; i < 18 + 1; ++i)
{
TextBox.AppendText("name" + i.ToString() + " ");
}
TextBox.AppendText(Environment.NewLine);
}
Answer the question
In order to leave comments, you need to log in
The mod
operation will help to correctly make a circular shift
How it works:
0 mod 8 = 0
1 mod 8 = 1
...
7 mod 8 = 7
8 mod 8 = 0
9 mod 8 = 1
10 mod 8 = 2
...
16 mod 8 = 0
and so on in a circle
int start = 11, last = 18;
int[] arr = Enumerable.Range(start, last - start + 1).ToArray();
for (int j = 0; j < count; j++) {
for (int i = 0; i < count; i++) {
Console.Write($"name{arr[(i + j) % count]} ");
}
Console.WriteLine();
}
If I understand correctly, then you just take, iterate over the array and connect the string with the value from the array:
// Fix2
var count = 5;
var counter = 0;
var min = 1;
var max = 6;
do
{
var str = "";
for (int i = min; i < max + 1; ++i)
str += $"name{i} ";
Console.Write(str + '\n');
++counter;
} while (counter < count);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question