You are not logged in. Please login at www.codechef.com to post your questions!

×

getting runtime error c#

static int count; static List<int> numbers = new List<int>(); 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);

asked 19 Feb, 14:54

cod_rush's gravatar image

0★cod_rush
1
accept rate: 0%


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. :)

link
This answer is marked "community wiki".

answered 19 Feb, 19:55

satyapriya98's gravatar image

2★satyapriya98
1
accept rate: 0%

wikified 19 Feb, 20:01

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×545

question asked: 19 Feb, 14:54

question was seen: 49 times

last updated: 19 Feb, 20:01