Need to calculate number of ships. Ships are presented as “battleship” game.“1” represent ship, “0” represents water. C#
C#:
namespace Ships
{
class Program
{
static int[,] ships = new int[10, 10] {
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, },
{ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, },
{ 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, },
{ 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, },
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, }
};
static void Main(string[] args)
{
int count = 0;
// count ships here
Console.WriteLine(count);
Console.ReadLine();
}
}
}
Last edited by a moderator: