00:01
Okay, so in this question we want to write a recursive method called countdown.
00:06
It will count down from 10 to from n, any number n, from n to 1, and then print blast.
00:16
There's no language specify, although it says to write a main method that prompts the user to enter a positive integer and countdown to one from that number.
00:32
I will assume it's c+ + but it should be the same in any language.
00:40
So i'm going to, here i have a basic c+ + program which does absolutely nothing, as you can see.
00:46
And we're going to start by asking for the user input.
00:51
So i'm going to use the standard library function for, to output things on the screen.
00:58
I'm going to enter p, enter, enter, and and then i'm going to have an end of line and here i'm going to use cn so out this tool i'll put things on the screen and then i'm going to take my n with cn and is for to take input because it's c+ + i will need to declare my int and now if i run this program and i enter for example, 10, nothing happens, but at least we know it's working.
01:47
Well, there is no bug and we can continue.
01:52
Of course it does nothing because we haven't programmed to do anything else than ask for an n and input.
02:00
So here i'm going to have a function called countdown and it's going to be a void function which means it won't return anything, it will simply output some vat.
02:12
Value.
02:13
Avoid countdown is going to take an integer n as a parameter and basically we want the function to be recursive.
02:33
So we need a stopping criteria.
02:35
If n is less than one, then we can output.
02:49
In other language it would be print, but in c+ + it's the out.
02:53
Okay, i'll put blast off and have an end of line.
03:04
Otherwise, we will print, we will not print.
03:09
We will else, we will see out.
03:19
Again, i will simply copy and paste this.
03:23
And then we will output our n on the screen and then i forgot to put my curly braces here.
03:33
Here and we're going to try to you do good spacing so it's readable.
03:43
I'm going to output my n and then we want the function to be recursive.
03:51
I'm going to call countdown of n minus 1.
03:59
And of course e+ + requires you to write a semicolon and in my main i will simply call countdown of n let's try to run this program...