Answer:
def sum_cubes(n):
if n == 1:
return 1
else:
return n * n * n + sum_cubes(n-1)
print(sum_cubes(3))
Explanation:
Create a function called sum_cubes that takes one parameter, n
If n is equal to 1, return 1. Otherwise, calculate the cube of n, and add it to the sum_cubes function with parameter n-1
If we want to calculate the cubes of the first 3 numbers:
sum_cubes(3) = 3*3*3 + sum_cubes(2)
sum_cubes(2) = 2*2*2 + sum_cubes(1)
sum_cubes(1) = 1
If you substitute the values from the bottom, you get 27+8+1 = 36
Answer:
The program to this question can be given as follows:
Program:
//class
public class factorial //defining class
{
//method fact
public static long fact(int x1) //defining method fact
{
//conditional statement
if (x1 <= 1) //if block checks parameter value less then equal to 1
{
return 1; //return value
}
else //else part
{
return (fact(x1 - 1) * (long) x1); //return factors using recursive function
}
}
//method main
public static void main(String[] args) //defining main method
{
long data=fact(5);//defining variable that holds function value
System.out.println("Factorial is: "+data); //print value
}
}
Output:
Factorial is: 120
Explanation:
In the above java program, a class is "factorial" is defined, inside the class, a static method "fact" is declared, that accepts an integer parameter that is "x1" and returns a long value, inside this method a conditional statement is used.
- If the block it checks parameter value is less then equal to 1, if this condition is true, it will return 1 when this condition is not true. It will go in else part.
- In else part, it uses a recursive function to calculate factorial of a number and return its value.
- Then the main method is defined, inside this method a long variable "data" is defined, that call and holds fact function return value, and in the next line, the print function is used to print the data variable value.
In order to customize a shape, Kelli should first add a basic shape and select it. After that, she needs to access the format tab where she can find the option to edit the selected shape. She can modify the selected shape or change it to a free-form according to her needs.
<u>Explanation:</u>
Microsoft PowerPoint provides an easy way for customizing the shapes according to the needs of the user.
Although PowerPoint provides many basic shapes that suit the need of most of the users but in exceptional cases, changes are always welcome. So in order to customize a shape, she should follow the steps which has been explained above.
int firstNumber,secondNumber = -1, duplicates = 0;
do {
cin >> firstNumber;
if ( secondNumber == -1) {
secondNumber = firstNumber;
}else {
if ( secondNumber == firstNumber )
duplicates++;
else
secondNumber = firstNumber;
}
} while(firstNumber > 0 );
cout << duplicates;