Need to calculate the number of ships. Ships are presented as a “battleship” game.“1” represents a 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;
// code write here
Console.WriteLine(count);
Console.ReadLine();
}
}
}
Last edited: