Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

# Insert the missing code in the following code fragment- This fragment.docx

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

1 von 2 Anzeige

# Insert the missing code in the following code fragment- This fragment.docx

Insert the missing code in the following code fragment. This fragment is intended to recursively compute xn, where x and n are both non-negative integers:
public int power(int x, int n)
{
if (n == 0)
{
____________________
} else
{
return x * power(x, n - 1);
} }
a) return 1;
b) return x;
c) return power(x, n - 1);
d) return x * power(x, n - 1);
Solution
And: a) return 1;
public int power(int x, int n){
// base case, zero power of any number is 1
if(n==0){
return 1;
}
else{
return x*pow(x, n-1);
}
}
.

Insert the missing code in the following code fragment. This fragment is intended to recursively compute xn, where x and n are both non-negative integers:
public int power(int x, int n)
{
if (n == 0)
{
____________________
} else
{
return x * power(x, n - 1);
} }
a) return 1;
b) return x;
c) return power(x, n - 1);
d) return x * power(x, n - 1);
Solution
And: a) return 1;
public int power(int x, int n){
// base case, zero power of any number is 1
if(n==0){
return 1;
}
else{
return x*pow(x, n-1);
}
}
.

Anzeige
Anzeige

## Weitere Verwandte Inhalte

Anzeige

### Insert the missing code in the following code fragment- This fragment.docx

1. 1. Insert the missing code in the following code fragment. This fragment is intended to recursively compute xn, where x and n are both non-negative integers: public int power(int x, int n) { if (n == 0) { ____________________ } else { return x * power(x, n - 1); } } a) return 1; b) return x; c) return power(x, n - 1); d) return x * power(x, n - 1); Solution And: a) return 1; public int power(int x, int n){
2. 2. // base case, zero power of any number is 1 if(n==0){ return 1; } else{ return x*pow(x, n-1); } }