Prime b

Prime b

  • NA
  • 810
  • 345.8k

Problem with loops

Jan 4 2012 11:42 PM
So this is the problem

Write a console-based application that displays all
even numbers from 2 to 100, inclusive.

This is my solution to it

            double max = 50;
            double math;
            for (int x = 1; x <= max; ++x)
            {
                math = x * 2;
                Console.WriteLine(math);
            }

So simple lol, but it took me a minute to think of it. Also any other way to do this problem?

Then there's part B, Create a GUI application that displays all the even numbers
from 2 to 100 inclusive when the user clicks a button.

This is my solution

   private void button1_Click(object sender, EventArgs e)
        {
            double max = 50;
            double math;
            for (int x = 1; x <= max; ++x)
            {
                math = x * 2;
                label1.Text = String.Format("{0}", math);
            }

But all it does is display 100, the only number..


Answers (2)