Food

CSharp · Console

/Program.cs

using System;
				

public class Program {
  private static char[,] ToTable(string value, int colCount) {
    if (value is null)
      throw new ArgumentNullException(nameof(value));

    if (colCount <= 0)
      throw new ArgumentOutOfRangeException(nameof(colCount));

    char[,] result = new char[
      value.Length / colCount + (value.Length % colCount == 0 ? 0 : 1), 
      colCount];
	  
	for (int r = 0; r < result.GetLength(0); ++r) 
      for (int c = 0; c < result.GetLength(1); ++c)   
        result[r, c] = 'X';  

    for (int i = 0; i < value.Length; ++i)
      result[i / result.GetLength(1), i % result.GetLength(1)] = value[i];

    return result;
  }
	
  public static void Main()	{
    string test =  "DELICIOUS FOOD";
	  
	var result = ToTable(test, 5);  
	  
	for (int r = 0; r < result.GetLength(0); ++r) {
		for (int c = 0; c < result.GetLength(1); ++c) {
			Console.Write(result[r, c]);
		}
		
		Console.WriteLine();
	}
  }
}
;