getting runtime error c#

static int count;
static List numbers = new List();
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());

        int k = Convert.ToInt32(Console.ReadLine());

        for (int i = 0; i < 5; i++)
        {
            numbers.Add(Convert.ToInt32( Console.ReadLine()));
        }
        foreach (var item in numbers)
        {
            if (item % k == 0)
                count++;
        }
        Console.Write(count);

You might be running your program without any inputs and getting a Runtime Eception , DivideByZeroException. This is because the default value assigned to k will be zero if you are not reading the value of k as input. Try giving some inputs and you wonn’t get any runtime error, except when k=0. :slight_smile: