public static void Main (string[] args)
{
int m = 19;
int n = 2;
m = Recursionmult (M, n);
Recursiondivision (M, n);
Test
m = 35;
n = 4;
Console.WriteLine ("\nm=" + M + ", n=" + N);
m = Recursionmult (M, n);
Recursiondivision (M, n);
m = 40;
n = 5;
Console.WriteLine ("\nm=" + M + ", n=" + N);
m = Recursionmult (M, n);
Recursiondivision (M, n);
m = 21;
n = 1;
Console.WriteLine ("\nm=" + M + ", n=" + N);
m = Recursionmult (M, n);
Recursiondivision (M, n);
Console.read ();
}
public static int Recursionmult (int m, int n)
{
if (n <= m)
{
Console.WriteLine (n + "");
n = n * 2;
Return Recursionmult (M, n);
}
return n;
}
public static int recursiondivision (int m, int n)
{
if (M > N)
{
m = M/2;
Console.WriteLine (M + "");
Return Recursiondivision (M, n);
}
return n;
}
Test results:
m=19,n=2
2 4 8 16 16 8 4 2
M=35,n=4
4 8 16 32 32 16 8 4
M=40,n=5
5 10 20 40 40 20 10 5
M=21,n=1
1 2 4 8 16 16 8 4 2 1
Do not use local variables and for loops or other loops to print out strings like m=19,n=2 2 4 8 16 16 8 4 2