Results 1 to 29 of 29

Thread: [2.0] Could this code be impossible to write??

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    [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?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

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

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [2.0] Could this code be impossible to write??

    c# Code:
    1. for(int i = 7; i >= 1; --i)
    2. {
    3.     for(int x = 7; x >= i; --x)
    4.     {
    5.          Console.Write(i);
    6.     }
    7.     Console.WriteLine();
    8. }

    Alternatively:
    c# Code:
    1. for(int i = 7; i >= 1; --i)
    2. {
    3.     for(int x = 0; x <= 7-i; ++x)
    4.     {
    5.          Console.Write(i);
    6.     }
    7.     Console.WriteLine();
    8. }
    Show Appreciation. Rate Posts.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

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

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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)

  11. #11
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [2.0] Could this code be impossible to write??

    Code:
    Buffer = new String(i.ToString()[0], iNum - i + 1)
    Show Appreciation. Rate Posts.

  12. #12

  13. #13
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  14. #14
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [2.0] Could this code be impossible to write??

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

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2.0] Could this code be impossible to write??

    My original logic code example in C3 (finally lol).
    c# Code:
    1. private void button1_Click(object sender, EventArgs e)
    2. {
    3.     int z = 1;
    4.     for(int i = 7; i >= 1; --i)
    5.     {
    6.         z = 7-i;
    7.         for (int x = 0; x <= z; --z)
    8.         {
    9.             textBox1.Text = textBox1.Text + i;
    10.         }
    11.         textBox1.Text = textBox1.Text + Environment.NewLine;
    12.     }
    13. }
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  16. #16
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: [2.0] Could this code be impossible to write??

    How to do it on a WinForm ? (as there is no Print method)
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  17. #17
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [2.0] Could this code be impossible to write??

    Quote 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.
    Show Appreciation. Rate Posts.

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  19. #19

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] Could this code be impossible to write??

    cuz everyone loves a big number triangle as a form background picture!

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  21. #21
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Could this code be impossible to write??

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

  22. #22
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

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

  23. #23
    Lively Member
    Join Date
    Feb 2007
    Location
    Toronto, ON
    Posts
    117

    Re: [2.0] Could this code be impossible to write??

    Quote 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!

  24. #24
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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 Attached Images  
    I don't live here any more.

  25. #25
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

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

  26. #26
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Could this code be impossible to write??

    Do it properly smartarse.
    I don't live here any more.

  27. #27
    Lively Member
    Join Date
    Feb 2007
    Location
    Toronto, ON
    Posts
    117

    Re: [2.0] Could this code be impossible to write??

    Quote Originally Posted by wossname
    Do it properly smartarse.
    Haha..smartass says the guy that tried to pull that stunt to begin with

  28. #28
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  29. #29

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] Could this code be impossible to write??

    Quote 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
  •  



Click Here to Expand Forum to Full Width