Question

do-while 5. Write a program in C# Sharp to display the patter like a diamond.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Pattern
{
public static void Main(string[] args)
{
int i=1,j=1,k=1,bl=0;
do {
//To add required predceding blank space
bl=(9-i)/2;
j=0;
do {
Console.Write(" ");
j++;
} while(j<=bl);
//To add required number of asterisks
k=1;
do {
Console.Write("*");
k++;
} while(k<=i);
//Next line
Console.WriteLine("");
//Incrementing count of asterisks
i=i+2;
} while(i<=9);
//Similar code as above but reverse pattern
i=7;
do {
bl=(9-i)/2;
j=0;
do {
Console.Write(" ");
j++;
} while(j<=bl);
k=1;
do {
Console.Write("*");
k++;
} while(k<=i);
Console.WriteLine("");
//Decrementing count of asterisks
i=i-2;
} while(i>=1);
}
}

Add a comment
Know the answer?
Add Answer to:
do-while 5. Write a program in C# Sharp to display the patter like a diamond.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT