Воссоздать перебрать каждый индекс с каждым столько раз каково число n - C#
Формулировка задачи:
// double[] data = new double[10];
// int n = количество циклов
for(int x1 = 1; x1 < data.count(); x1++)
{
for(int x2 = 1; x2 < data.count(); x2++)
{
for(int x3 = 1; x3 < data.count(); x3++)
{
//
}
}
}Решение задачи: «Воссоздать перебрать каждый индекс с каждым столько раз каково число n»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static int circleall = 3; // сколько кругов нужно пройти
static int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}
static void Main(string[] args)
{
int indeks = 0;
char vremenijSimvol;
StringBuilder stroka = new StringBuilder("12345");
int dlinaStroki = stroka.Length;
int kolicestvoVariantov = factorial(dlinaStroki);
for (int x = 0; x < circleall; x++)
{
Console.WriteLine(stroka);
for (int z = 0; z < kolicestvoVariantov - 1; z++)
{
if (indeks + 1 >= dlinaStroki) indeks = 0;
vremenijSimvol = stroka[indeks];
stroka[indeks] = stroka[indeks + 1];
stroka[indeks + 1] = vremenijSimvol;
Console.WriteLine(stroka);
indeks++;
}
}
Console.ReadKey();
}
}
}