1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RotateArray
{
class Program
{
static void Main(string[] args)
{
char[] arr = new char[] { 'A', 'B', 'C',
'D', 'E', 'F' };
int index = 0;
Console.WriteLine("valeur de l'array initial :");
impression(arr, arr.Length, index);
Console.WriteLine();
Console.WriteLine("Entrer un nombre entre 0 et " + (arr.Length - 1).ToString() +" : ");
saisie(arr);
// exit
Console.WriteLine ("appyer sur touche pour quitter");
Console.ReadKey();
}
public static void saisie(char[] myarr)
{
bool b = true;
int index = 0;
while (b)
{
if (int.TryParse(Console.ReadLine(), out index))
{
if (index >= 0 && index < myarr.Length)
{
impression(myarr, myarr.Length, index);
Console.WriteLine();
}
else
{
Console.WriteLine("nombre saisi n'est pas dans la plage");
b = false;
}
}
}
}
// function to print circular array
public static void impression(char[] a, int length,int position)
{
// print from ind-th index to
// (n+i)th index.
for (int i = position; i < length + position; i++)
Console.Write(a[(i % length)] + " ");
}
}
} |
Partager