using System;
namespace NumberProduct{class Program{static void Main(string[] args){Console.WriteLine("Enter a number: ");string number = Console.ReadLine();
}
using System;
namespace NumberProduct
if (IsValidInput(number)){
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number: ");
string number = Console.ReadLine();
{
int firstTwoDigitsProduct = GetDigitsProduct(number, 0, 1);
int lastTwoDigitsProduct = GetDigitsProduct(number, number.Length - 2, number.Length - 1);
int firstAndLastDigitProduct = GetDigitsProduct(number, 0, number.Length - 1);
Console.WriteLine("Product of first two digits: " + firstTwoDigitsProduct);
Console.WriteLine("Product of last two digits: " + lastTwoDigitsProduct);
Console.WriteLine("Product of first and last digits: " + firstAndLastDigitProduct);
}
else
{
Console.WriteLine("Invalid input. Please enter a valid number.");
}
}
static bool IsValidInput(string number)
{
foreach (char c in number)
{
if (!Char.IsDigit(c) && c != 'A' && c != 'B' && c != 'C' && c != 'D' && c != 'E' && c != 'F')
{
return false;
}
}
return true;
}
static int GetDigitsProduct(string number, int index1, int index2)
{
int digit1, digit2;
if (Char.IsDigit(number[index1]))
{
digit1 = int.Parse(number.Substring(index1, 1));
}
else
{
digit1 = GetHexValue(number[index1]);
}
if (Char.IsDigit(number[index2]))
{
digit2 = int.Parse(number.Substring(index2, 1));
}
else
{
digit2 = GetHexValue(number[index2]);
}
return digit1 * digit2;
}
static int GetHexValue(char hex)
{
switch (hex)
{
case 'A':
return 10;
case 'B':
return 11;
case 'C':
return 12;
case 'D':
return 13;
case 'E':
return 14;
case 'F':
return 15;
default:
return 0;
}
}
}
}