Ex 23. Use a loop to count the number of values, between 1000 and 2000, that are divisible by 7. Display the count in a Messagebox.
namespace Final_Review_23
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDisplay_Click(object sender, EventArgs e)
{
string counterNo = string.Empty;
int result = 0;
for (int counter = 1000; counter <= 2000; counter++)
{
if (counter % 7 == 0)
{
result++;
counterNo += counter.ToString() + " ";
}
}
MessageBox.Show(counterNo + "\n\nTotal: " + result.ToString());
//for only counter no:
// MessageBox.Show(result.ToString());
}
}
}
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDisplay_Click(object sender, EventArgs e)
{
string counterNo = string.Empty;
int result = 0;
for (int counter = 1000; counter <= 2000; counter++)
{
if (counter % 7 == 0)
{
result++;
counterNo += counter.ToString() + " ";
}
}
MessageBox.Show(counterNo + "\n\nTotal: " + result.ToString());
//for only counter no:
// MessageBox.Show(result.ToString());
}
}
}

No comments:
Post a Comment