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..
Loading
Shen HengbinPosted Jan 5, 2012, 12:48 AM
double math;
StringBuilder sb = new StringBuilder();
for (int x = 1; x <= max; ++x)
{
math = x * 2;
if (sb.Length > 0) sb.Append(",");
sb.AppendFormat("{0}", math);
}
label1.Text = sb.ToString();
Jignesh TrivediPosted Jan 4, 2012, 11:56 PM
your solution look good.
double max = 100;
for (int x = 1; x <= max; ++x)
{
math = x % 2;
if (math == 0)
{
Console.WriteLine(x);
}
}