Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

http://i74.photobucket.com/albums/i249/wapak00/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

  • Leaders
Posted

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).

[/Quote]

[sIGPIC]e[/sIGPIC]
Posted

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:

 

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);
               }
           }
       }
   }
}

Posted

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.

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...