Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1 212
32123
4321234
print this in console window
Posted

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
If you get stuck on a particular bit, then ask about that - but this is your task, and we will not do it for you!


I did It....By Using Five If Conditions......


:laugh:
Look at each if condition. If "i" is "n" then you start "k" from "n"...so why check the "i" value, instead just start the "k" loop from "i"?

Time to put you out of your misery, you are close enough!
Here is my version:
C#
for (int i = 1; i <= 5; i++)
    {
    for (int k = i; k > 1; k--)
        {
        Console.Write(k + " ");
        }
    for (int j = 1; j <= i; j++)
        {
        Console.Write(j + " ");
        }
    Console.WriteLine();
    }

Do you see what I mean now? Does that make sense?
 
Share this answer
 
v2
Comments
sashkhdr 26-Oct-14 3:19am    
for(int i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
console.write(j+" ");
}
Console.Writeline();
}
.....................
After that im not getting plz help
OriginalGriff 26-Oct-14 3:30am    
The first thing to notice is that C# is *case sensitive* - so "console" is not the same as "Console", and "Writeline" is not the same as "WriteLine". And unless you already have a variable called "j", you need to specify the type of that as well. Correct those and you code should at least compile.

After that, how does your output differ from the homework question?
That should give you a big hint as to where you need to start - going down, not up! Try that, and tell me what happens with your new code.
sashkhdr 26-Oct-14 3:44am    
I tried by using jagged array....

static void Main(string[] args)
{
int[][] arr = new int[4][] ;
arr[0] = new int[] { 1 };
arr[1] = new int[] {2, 1, 2 };
arr[2] = new int[] {3,2, 1, 2, 3 };
arr[3] = new int[] {4,3,2, 1, 2, 3,4};
for (int i = 0; i < arr.Length; i++)
{
int[] num = arr[i];
for (int j = 0; j < num.Length; j++)
{
Console.Write(num[j]+" ");
}
Console.WriteLine();
}


is it correct..i cont solve by using for loop by taking num in loop
OriginalGriff 26-Oct-14 3:56am    
Stop and think: how would you do it by hand?
You would have an outer loop to control the number of lines: you have that.
But inside that loop, what would you do?
What number would you start by printing on a line? What number is next?

These aren't trick questions - you could do it very easily with a pen and paper, so it's a case of "working out" how you do that, and translating it into code.

I'll help you, but it really is important that you make this "jump" by yourself - it's fundamental to developing!
sashkhdr 26-Oct-14 4:05am    
static void Main(string[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(j+" ");
}
Console.WriteLine();
}

....................................

after this What i have to do...plz help..or give some clue
C#
static void Main(string[] args)
       {
           for (int i = 1; i <= 5; i++)
           {
               for (int j = i; j > 1; j--)
               {
                   Console.Write(j+" ");
               }
               for (int k = 1; k <= i; k++)
               {
                   Console.Write(k+" ");
               }
               Console.WriteLine();
           }
       }
 
Share this answer
 

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