algorthim
-
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
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.
-
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.
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!
-
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
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?
-
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.
-
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.
-
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?
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.
-
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!
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!
-
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!
-
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.
-
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?
"For your next assignment, Mr. Norris, you are to apprehend a bad guy without using a roundhouse kick or doing any bodily harm."
-
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
I just checked the C# specification and saw no mention of "loops", so just use an "iteration statement". :-D