Mar 8th, 2007, 04:42 PM
#1
Thread Starter
Frenzied Member
[2.0] Could this code be impossible to write??
Hello,
Let's say the user inputs the number 7. THe program will output this:
Code:
7
66
555
4444
33333
222222
1111111
The rules my teacher stated is ONLY for loops. No if statements, just for loops. You can nest a for loop but that is all. Can anyone solve this?
Mar 8th, 2007, 04:53 PM
#2
Re: [2.0] Could this code be impossible to write??
Loop backwards using a counter variable to increment the printing of the loop value.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 8th, 2007, 04:57 PM
#3
Re: [2.0] Could this code be impossible to write??
Code:
For i = 7 to 1 step -1
for x = 1 to 7
conmsole.writeline(i);
next
next
Something like that.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 8th, 2007, 05:05 PM
#4
Thread Starter
Frenzied Member
Re: [2.0] Could this code be impossible to write??
rob u could rack up a triple post if u translated that to c#. nah i got it don't worry thanks i'll try it out
Mar 8th, 2007, 05:07 PM
#5
Thread Starter
Frenzied Member
Re: [2.0] Could this code be impossible to write??
yea it doesn't work i just get this as a result:
Code:
7777777
6666666
5555555
4444444
3333333
2222222
1111111
using... this code:
Code:
for (int i = 7; i >= 1; i--) {
for (int x = 1; x <= 7; x++) {
System.out.print(i);
}
System.out.println();
}
Mar 8th, 2007, 05:08 PM
#6
Re: [2.0] Could this code be impossible to write??
lol, naw. I just thought some pseudocode would be better explaination.
The write needs to write on the same line. In VB the semicolon identifies a print continuation. Oh add a new line print after the inner loop to get it to move to the next line.
Im sure there may be better .net ways to do it but this was my first thought.
Edit: Should be x = 1 to z where z would be 7 - i
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 8th, 2007, 05:12 PM
#7
Re: [2.0] Could this code be impossible to write??
c# Code:
for(int i = 7; i >= 1; --i)
{
for(int x = 7; x >= i; --x)
{
Console.Write(i);
}
Console.WriteLine();
}
Alternatively:
c# Code:
for(int i = 7; i >= 1; --i)
{
for(int x = 0; x <= 7-i; ++x)
{
Console.Write(i);
}
Console.WriteLine();
}
Mar 8th, 2007, 05:12 PM
#8
Re: [2.0] Could this code be impossible to write??
Code:
for i = 7 to 1 step -1
z = z + 1
for x = 1 to z
conmsole.writeline(i);
next
next
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 8th, 2007, 05:19 PM
#9
Thread Starter
Frenzied Member
Re: [2.0] Could this code be impossible to write??
gracias!! it works great:
Code:
for (int i = n; i >= 1; --i) {
for (int x = n; x >= i; --x) {
System.out.print(i);
}
System.out.println();
}
Mar 8th, 2007, 05:21 PM
#10
Re: [2.0] Could this code be impossible to write??
without nested loops:
Code:
int iNum = 0;
Console.WriteLine("Input A Value");
string sNum = Console.ReadLine();
if (int.TryParse(sNum, out iNum))
{
string Buffer = "";
for (int i = iNum; i > 0; --i)
{
Console.WriteLine(Buffer = new String(i.ToString()[0], iNum - i + 1));
}
}
else
{
Console.WriteLine("No Good!");
}
Console.ReadLine();
(i'm answering this as much for my benefit as the posters - so if anyone can tell me if i'm doing something i shouldn't be, I'd like to hear it)
edit: slight correction (+1)
Last edited by bushmobile; Mar 8th, 2007 at 05:25 PM .
Mar 8th, 2007, 05:31 PM
#11
Re: [2.0] Could this code be impossible to write??
Code:
Buffer = new String(i.ToString()[0], iNum - i + 1 )
Mar 8th, 2007, 05:31 PM
#12
Re: [2.0] Could this code be impossible to write??
Mar 8th, 2007, 05:38 PM
#13
Re: [2.0] Could this code be impossible to write??
the connection is too slow today.
Furthermore, the i.ToString()[0] won't work good if number is a more than 9. It will display only the first digit.
I don't know if it matters.
Mar 8th, 2007, 05:41 PM
#14
Re: [2.0] Could this code be impossible to write??
Originally Posted by
Harsh Gupta
tFurthermore, the i.ToString()[0] won't work good if number is a more than 9. It will display only the first digit.
I don't know if it matters.
yeah, I was aware of that - I assumed the question only meant for single digit numbers, otherwise the triangle doesn't make sense.
Mar 8th, 2007, 05:46 PM
#15
Re: [2.0] Could this code be impossible to write??
My original logic code example in C3 (finally lol).
c# Code:
private void button1_Click(object sender, EventArgs e)
{
int z = 1;
for(int i = 7; i >= 1; --i)
{
z = 7-i;
for (int x = 0; x <= z; --z)
{
textBox1.Text = textBox1.Text + i;
}
textBox1.Text = textBox1.Text + Environment.NewLine;
}
}
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 8th, 2007, 05:46 PM
#16
Re: [2.0] Could this code be impossible to write??
How to do it on a WinForm ? (as there is no Print method)
Mar 8th, 2007, 05:58 PM
#17
Re: [2.0] Could this code be impossible to write??
Originally Posted by
iPrank
How to do it on a WinForm ? (as there is no Print method)
using GDI+, look for Graphics.DrawString() (+6 overloaded) functions. Works for functions having PaintEventArgs parameter.
Last edited by Harsh Gupta; Mar 9th, 2007 at 03:24 AM .
Mar 8th, 2007, 08:23 PM
#18
Re: [2.0] Could this code be impossible to write??
Why would you want to draw this directly on a form?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 8th, 2007, 09:47 PM
#19
Thread Starter
Frenzied Member
Re: [2.0] Could this code be impossible to write??
cuz everyone loves a big number triangle as a form background picture!
Mar 9th, 2007, 04:05 AM
#20
Re: [2.0] Could this code be impossible to write??
So what grade did we get?
Maybe we should have a homework forum?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 10th, 2007, 11:51 AM
#21
Re: [2.0] Could this code be impossible to write??
Originally Posted by
Fromethius
Hello,
Let's say the user inputs the number 7. THe program will output this:
Code:
7
66
555
4444
33333
222222
1111111
The rules my teacher stated is ONLY for loops. No if statements, just for loops. You can nest a for loop but that is all. Can anyone solve this?
Code:
Console.Write("7\n66\n555\n4444\n33333\n222222\n1111111\n");
I don't live here any more.
Mar 10th, 2007, 12:10 PM
#22
Re: [2.0] Could this code be impossible to write??
Bad wossname, you didn't use a for() loop.
Code:
for (;false;);
Console.Write("7\n66\n555\n4444\n33333\n222222\n1111111\n");
Mar 12th, 2007, 02:50 AM
#23
Lively Member
Re: [2.0] Could this code be impossible to write??
Originally Posted by
penagate
Bad wossname, you didn't use a for() loop.
Code:
for (;false;);
Console.Write("7\n66\n555\n4444\n33333\n222222\n1111111\n");
Code:
for (int i = 0; i == 0; ++i)
{
Console.WriteLine("7\n66\n555\n4444\n33333\n222222\n1111111\n");
}
there...solved taht problem!
Mar 12th, 2007, 07:46 AM
#24
Re: [2.0] Could this code be impossible to write??
I wonder if you guys can print this output without using an if statement (the ?: operator is not allowed either)...
Attached Images
I don't live here any more.
Mar 12th, 2007, 07:52 AM
#25
Re: [2.0] Could this code be impossible to write??
Console.Write("18\n18\n16 16 14\n14\n12 12 10\n10\n8 8 6\n6\n4 4 2\n2\n0 0");
Mar 12th, 2007, 07:56 AM
#26
Re: [2.0] Could this code be impossible to write??
Do it properly smartarse.
I don't live here any more.
Mar 12th, 2007, 01:56 PM
#27
Lively Member
Re: [2.0] Could this code be impossible to write??
Originally Posted by
wossname
Do it properly smartarse.
Haha..smartass says the guy that tried to pull that stunt to begin with
Mar 13th, 2007, 12:47 PM
#28
Re: [2.0] Could this code be impossible to write??
Yeah but the first time it was original.
I don't live here any more.
Mar 14th, 2007, 05:29 AM
#29
Thread Starter
Frenzied Member
Re: [2.0] Could this code be impossible to write??
Originally Posted by
RobDog888
So what grade did we get?
Maybe we should have a homework forum?
Twas extra credit. I now have a 105 in programming class
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width