Visual C# 5.33 (Checkerboard Pattern of Asterisks)

This Solution is for the “Checkerboard Pattern of Asterisks” of chapter 5 in the textbook; Visual c# How to program 6th edition by Deitel.

//Date: 5/2/17
/*Description:
a program that uses only the output
statements supplied to display the
checkerboard pattern presented in
the exercise */
using System;
class Program
{
static void Main()
{
int counter = 1; //initializes variable counter to 1

//while statement checks counter, if so proceeds
while (counter <= 8)
{
int stars = 1;//initializes variable stars to 1

//checks if the remainder of variale counter / 2 = 0
if (counter % 2 == 0)
Console.Write(” “);//if so prints a blank space

//nested while statement checks count of stars, if so proceeds
while (stars <= 8)
{
Console.Write(“* “);//if so prints a “star”
++stars;//increases star count by 1
}
Console.WriteLine(” “);//prints a blank space moves down to next line
++counter;//increases star count by 1
}
}
}

output:

* * * * * * * *
 * * * * * * * *
* * * * * * * *
 * * * * * * * *
* * * * * * * *
 * * * * * * * *
* * * * * * * *
 * * * * * * * *
Press any key to continue . . .

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s