Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. algorthim

algorthim

Scheduled Pinned Locked Moved C#
12 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S SVb net

    i need to make method pass number integer as 3 and print on screan 3 2 1 0 1 2 3 but not use loop at the method and not return any value

    123

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #2

    Well, you could do this:

    private void PrintNumbers(int number)
    {
      Console.WriteLine("3 2 1 0 1 2 3");
    }
    

    And then call it with PrintNumbers(3); Alternatively, you could do this with a recursive method call.

    Deja View - the feeling that you've seen this post before.

    My blog | My articles

    L S 2 Replies Last reply
    0
    • P Pete OHanlon

      Well, you could do this:

      private void PrintNumbers(int number)
      {
        Console.WriteLine("3 2 1 0 1 2 3");
      }
      

      And then call it with PrintNumbers(3); Alternatively, you could do this with a recursive method call.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #3

      Pete O'Hanlon wrote:

      you could do this with a recursive method call

      a recursion with a method that "does not return a value"? so a class member would be used to make things ugly. What will they come up with next? :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Happy 2008!


      B 1 Reply Last reply
      0
      • S SVb net

        i need to make method pass number integer as 3 and print on screan 3 2 1 0 1 2 3 but not use loop at the method and not return any value

        123

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #4

        SVb.net wrote:

        but not use loop at the method and not return any value

        I want this nail banged into this drywall, but you're not to use a hammer and you're not allowed to use the end of a screwdriver either! Whatever will this stupid teachers come up with next?

        P P 2 Replies Last reply
        0
        • P Pete OHanlon

          Well, you could do this:

          private void PrintNumbers(int number)
          {
            Console.WriteLine("3 2 1 0 1 2 3");
          }
          

          And then call it with PrintNumbers(3); Alternatively, you could do this with a recursive method call.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          S Offline
          S Offline
          SVb net
          wrote on last edited by
          #5

          but you don't know what number maybe 3 or 4 or 18 ...etc

          123

          P B 2 Replies Last reply
          0
          • S SVb net

            but you don't know what number maybe 3 or 4 or 18 ...etc

            123

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #6

            It's not my fault that your specification was vague. You asked " need to make method pass number integer as 3 and print on screan 3 2 1 0 1 2 3 but not use loop at the method and not return any value" and I gave you a method to do that. I'm not responsible for your scope creep.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            J 1 Reply Last reply
            0
            • J J4amieC

              SVb.net wrote:

              but not use loop at the method and not return any value

              I want this nail banged into this drywall, but you're not to use a hammer and you're not allowed to use the end of a screwdriver either! Whatever will this stupid teachers come up with next?

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #7

              J4amieC wrote:

              I want this nail banged into this drywall, but you're not to use a hammer and you're not allowed to use the end of a screwdriver either!

              He could always use his head.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              1 Reply Last reply
              0
              • L Luc Pattyn

                Pete O'Hanlon wrote:

                you could do this with a recursive method call

                a recursion with a method that "does not return a value"? so a class member would be used to make things ugly. What will they come up with next? :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Happy 2008!


                B Offline
                B Offline
                benjymous
                wrote on last edited by
                #8

                It's quite possible to solve this in a recursive manner without having to use return values or class members. To the Original Poster: I'm guessing the whole point of this exercise is to demonstrate that you understand recursion. If you don't, then it's probably worth re-reading your course notes, as you won't learn anything if we just tell you the answer (which is incredibly simple.)

                -- Help me! I'm turning into a grapefruit! Buzzwords!

                1 Reply Last reply
                0
                • S SVb net

                  but you don't know what number maybe 3 or 4 or 18 ...etc

                  123

                  B Offline
                  B Offline
                  benjymous
                  wrote on last edited by
                  #9

                  In that case...

                  private void PrintNumbers(int number)
                  {
                  if( number == 3 )
                  {
                  Console.WriteLine("3 2 1 0 1 2 3");
                  }
                  else if( number == 4 )
                  {
                  Console.WriteLine("4 3 2 1 0 1 2 3 4");
                  }
                  else if( number == 18 )
                  {
                  Console.WriteLine("18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18");
                  }
                  else
                  {
                  Console.WriteLine("Invalid argument");
                  }
                  }

                  -- Help me! I'm turning into a grapefruit! Buzzwords!

                  1 Reply Last reply
                  0
                  • P Pete OHanlon

                    It's not my fault that your specification was vague. You asked " need to make method pass number integer as 3 and print on screan 3 2 1 0 1 2 3 but not use loop at the method and not return any value" and I gave you a method to do that. I'm not responsible for your scope creep.

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    J Offline
                    J Offline
                    J4amieC
                    wrote on last edited by
                    #10

                    Pete O'Hanlon wrote:

                    I'm not responsible for your scope creep.

                    Genuine LOL

                    1 Reply Last reply
                    0
                    • J J4amieC

                      SVb.net wrote:

                      but not use loop at the method and not return any value

                      I want this nail banged into this drywall, but you're not to use a hammer and you're not allowed to use the end of a screwdriver either! Whatever will this stupid teachers come up with next?

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #11

                      "For your next assignment, Mr. Norris, you are to apprehend a bad guy without using a roundhouse kick or doing any bodily harm."

                      1 Reply Last reply
                      0
                      • S SVb net

                        i need to make method pass number integer as 3 and print on screan 3 2 1 0 1 2 3 but not use loop at the method and not return any value

                        123

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #12

                        I just checked the C# specification and saw no mention of "loops", so just use an "iteration statement". :-D

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups