Write a program will start by asking the user for the size of the shape to print
ID: 3846465 • Letter: W
Question
Write a program will start by asking the user for the size of the shape to print, and will then print the shape of the appropriate size. This is the pattern: all the lines between the first and last lines contain a single star. It is printed in the left-most column on one line, then being printed in the right-most column on the next line, then back to the left-most column, then the right-most column, etc. Here are some examples of sizes, and the shape that should be printed as a results: Feel free to write the entire program in main. You may assume that the user will only type in integer values greater than (or equal to 2 (so you don't have to validate the user's input) using System: namespace CSharpMidterm { class Class1 { static void Main (string[] args) {Explanation / Answer
I'll write the main function itself.
The given statement asks to print a different output than shown.
I'm writing code for both the cases.
1.) According to the statement. Each line has 1 star and it's on left most column in one line and right end column in next line and this follows.
CODE:
static void main(string[] args) {
string line = Console.ReadLine();
int n = int.Parse(line);
int i=0,j=0;
int flag=0;
for(i=0;i<n;i++)
{
if(flag==0)
{Console.WriteLine("*");
flag=1;}
else
{
Console.WriteLine(" ");
for(j=0;j<n-1;j++)
Console.WriteLine(" ");
Console.WriteLine("*");
flag=0;
}
}
}
OUTPUT:
5
*
(4 spaces) *
*
(4 spaces) *
*
2.) The following code is to obtain the output as the one drawn here.
public static void main(string[] args) {
string line = Console.ReadLine();
int n = int.Parse(line);
int i=0,j=0;
int flag=0;
for(i=0;i<n;i++)
{Console.WriteLine(" ");
for(j=0;j<n;j++)
Console.WriteLine("*");
}
}
OUTPUT:
5
*****
*****
*****
*****
*****
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.