Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i want star print in this shape
    *
   *
  *
 *
*
 *
  *
   *
    *
Posted
Updated 6-Apr-15 18:40pm
v3
Comments
Sascha Lefèvre 7-Apr-15 0:40am    
And what have you tried so far?
[no name] 7-Apr-15 0:42am    
Can u explain more ? question is not clear ?
King Fisher 7-Apr-15 0:59am    
He want to print * like the above format in Console Application. ;)
King Fisher 7-Apr-15 1:18am    
Have you tried anything ?

I think its your Interview question ,I faced the same question in my interview when I'm a fresher.

C#
using System;
class Program
{
    static void Main()
    {
        for (int i = 5; i >=0; i--)
        {
            //function();
            Console.WriteLine(Indent(i) + "*");
        }

    for (int i = 1; i<= 5; i++)
    {
        //function();
        Console.WriteLine(Indent(i) + "*");
    }
    Console.ReadKey();
}

public static string Indent(int count)
{
    return "".PadLeft(count);
}

}

And before you post your question try something with what you know.
 
Share this answer
 
v5
Comments
King Fisher 7-Apr-15 1:21am    
I don't know ,something went wrong while formatting :(
Dave Kreskowiak 7-Apr-15 1:25am    
When you see "questions" like this, do NOT post the code for it. Chances are it's not an interview question but a homework assignment.

You just gave him the answer without giving him the knowledge behind it.
King Fisher 7-Apr-15 1:31am    
Yes you are Right Sometimes , But the People who signup with Codeproject ,they hope CP can solve their Problems. :(
Sascha Lefèvre 7-Apr-15 1:41am    
You don't help them because they didn't even try themselves - they just take your answer, are done with their homework and come back for the next one..
King Fisher 7-Apr-15 2:13am    
Not All cases, this is his first question ,he didn't asked any question like this before.he may be Fresher or Student,I met some guys like this I assigned some task like this ,they took one to two days for this but didn't completed the task ,I Asked him what's the problem ? and he said i don't know how to search in Google and how to start ,where to start? because, very Poor quality of education in my State.
Solution 1:

protected void PrintGreater()
{

     for (int i = 5; i >=1; i--)
    {
        for (int j = 1; j < i; j++)
        {
            Response.Write("&nbsp;&nbsp;&nbsp;");
        }
        Response.Write("*"+ "<br/>");

    }

    for(int j=1;j<=5;j++)
        {<br />
            for(int i=1;i<j;i++)
            {

                Response.Write("&nbsp;&nbsp;&nbsp;");
            }
            Response.Write("*" + "<br/>");
        }
}



Solution 2:

protected void PrintGreater()
{

for (int i = 5; i >=1; i--)
{
for (int j = 1; j < i; j++)
{
Response.Write("   ");
}
Response.Write("*"+ "
");

}


for(int j=2;j<=5;j++)
{


for(int i=1;i<j;i++)
{
=""
="" response.write("&nbsp;&nbsp;&nbsp;");
="" }
="" response.write("*"="" +="" "<br="">");
}
}

hope this will work for you.

Happy coding :)
 
Share this answer
 
v2
Comments
Richard MacCutchan 7-Apr-15 8:14am    
You do not help people by doing their work for them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900