using System;
namespace App
{
class Program
{
static void Main(string[] args)
{
int number;
Console.Write("Enter a four-digit positive integer: ");
number = int.Parse(Console.ReadLine());
if (number < 1000 || number > 9999)
{
Console.WriteLine("Wrong number.\n");
}
else
{
int index = -1;
int counter = 0;
for (int i = 1000; i >= 10; i /= 10)
{
int digit = (number / i) % 10;
if (digit == 3)
{
index = counter;
break;
}
counter++;
}
if (index != -1)
{
Console.WriteLine("The number 3 exists at index {0}.", index);
}
else
{
Console.WriteLine("The number 3 does not exist");
}
}
Console.ReadLine();
}
}
}
Comments
Leave a comment