C# Gurus help! "For loop"

XxXnucronXxX

Newcomer
Joined
Dec 1, 2009
Messages
4
hi.. can someone teach me the code for doing the ff on C# : :confused::confused:

1.) a program that asks a number from a user and generate a figure below using For Loop statement

Examples:

Forloop.jpg



2.) a program that asks a number from a user and generate a figure below using For Loop statement

Examples:

Number: 5

5 5 5 5 5
4 4 4 4 4
3 3 3 3 3
2 2 2 2 2
1 1 1 1 1

Number: 4

4 4 4 4
3 3 3 3
2 2 2 2
1 1 1 1


thanks in advance.. i really hope you guys could help me.. :p
 
What have you got so far? You'll need one for loop within another.

Also, from the posting guidelines:
No homework assignments. Specific questions about parts of the assignment are permitted, but don't expect us to do your entire assignment for you. It is also permitted to ask for advice on getting started, or for general algorithms (pseudocode).
 
hi.. thanks for the reply..

here's what i've gotten so far..

yeah its a For Loop within another.. i just cant get it right.. :confused:

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace sw1
{
    class Program
    {
        static void Main(string[] args)
        {
            int inputNumber;

            System.Console.WriteLine("Enter the value for n: ");
            inputNumber = Convert.ToInt32(System.Console.ReadLine());

            for (int row = 1; row <= inputNumber; row++)
            {
                for (int column = 1; column <= ((inputNumber + 1) - inputNumber); column++)
                {
                    System.Console.SetCursorPosition(row - column, row);
                    System.Console.WriteLine(column);
                }
            }
        }
    }
}
 
Seriously, dont whanna be bad with u... but those moments spent on brainstorming this kind of simple algorithm are very usefull... as far as I remember when I was student felt a priceless pleasure resolving this by my own.
U should try to do it ur self. beleive me dude.
 
Try to get it working in a simplified way first, if you can get it to print the numbers descending correctly, even one on a line, then you have solved part of the problem.

If you can then get it to print the correct number of numbers on each line, even without formatting, you have then solved another part.

Finally solve the problem of aligining the numbers correctly into the output string.

If the problem can be turned into a series of simpler problems then each one you solve puts you nearer to the total solution, or if your approach doesn't work you have identified the failure in isolation from the other problems facing you - this helps you spot mistakes sooner.
 
Back
Top