CBSE Class 11 Computer Science Question 40 of 40

Data Handling — Question 25

Back to all questions
25
Question

Question 25

Write a program to compute (a + b)3 using the formula a3 + b3 + 3a2b + 3ab2

Solution
a = int(input("Enter a: "))
b = int(input("Enter b: "))
res = a ** 3 + b ** 3 + 3 * a ** 2 * b + 3 * a * b ** 2

print("Result =", res)
Output
Enter a: 3
Enter b: 5
Result = 512
Answer

a
=
int
(
input
(
"Enter a: "
))
b
=
int
(
input
(
"Enter b: "
))
res
=
a
**
3
+
b
**
3
+
3
*
a
**
2
*
b
+
3
*
a
*
b
**
2
print
(
"Result ="
,
res
)
Output
Enter a: 3
Enter b: 5
Result = 512