XxXnucronXxX Posted December 1, 2009 Posted December 1, 2009 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 Quote
Leaders snarfblam Posted December 1, 2009 Leaders Posted December 1, 2009 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] Quote [sIGPIC]e[/sIGPIC]
XxXnucronXxX Posted December 1, 2009 Author Posted December 1, 2009 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); } } } } } Quote
docflied Posted December 2, 2009 Posted December 2, 2009 Try the best algorithm for this : while (it wont work) { try again } :p Quote
XxXnucronXxX Posted December 2, 2009 Author Posted December 2, 2009 lol @ docflied please help.. anyone? :confused: Quote
docflied Posted December 2, 2009 Posted December 2, 2009 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. Quote
XxXnucronXxX Posted December 2, 2009 Author Posted December 2, 2009 yeah.. maybe you're right.. maybe i should do some more brainstorming.. Quote
Administrators PlausiblyDamp Posted December 2, 2009 Administrators Posted December 2, 2009 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.