Related Articles

# Program to evaluate the expression (√X+1)^6 + (√X-1)^6

• Last Updated : 22 Mar, 2021

Given a number . The task is to find the value of the below expression for the given value of  Examples:

Input: X = √2
Output: 198
Explanation = 198
Input: X = 3
Output: 4160

Approach: The idea is to use Binomial expression. We can take these two terms as 2 binomial expressions. By expanding these terms we can find the desired sum. Below is the expansion of the terms. Now put X= in EQ(1) Below is the implementation of above approach:

## C++

 // CPP program to evaluate the given expression#include using namespace std; // Function to find the sumfloat calculateSum(float n){    int a = int(n);     return 2 * (pow(n, 6) + 15 * pow(n, 4)            + 15 * pow(n, 2) + 1);} // Driver Codeint main(){    float n = 1.4142;     cout << ceil(calculateSum(n)) << endl;     return 0;}

## Java

 // Java program to evaluate the given expressionimport java.util.*; class gfg{// Function to find the sumpublic static double calculateSum(double n){    return 2 * (Math.pow(n, 6) + 15 * Math.pow(n, 4)            + 15 * Math.pow(n, 2) + 1);} // Driver Codepublic static void main(String[] args){    double n = 1.4142;    System.out.println((int)Math.ceil(calculateSum(n)));}}//This code is contributed by mits

## Python3

 # Python3 program to evaluate# the given expression import math #Function to find the sumdef calculateSum(n):         a = int(n)         return (2 * (pow(n, 6) + 15 * pow(n, 4)            + 15 * pow(n, 2) + 1))     #Driver Codeif __name__=='__main__':    n = 1.4142    print(math.ceil(calculateSum(n))) # this code is contributed by# Shashank_Sharma

## C#

 // C# program to evaluate the given expressionusing System;class gfg{// Function to find the sumpublic static double calculateSum(double n){    return 2 * (Math.Pow(n, 6) + 15 * Math.Pow(n, 4)            + 15 * Math.Pow(n, 2) + 1);} // Driver Codepublic static int Main(){    double n = 1.4142;    Console.WriteLine(Math.Ceiling(calculateSum(n)));    return 0;}}//This code is contributed by Soumik

## PHP

 

## Javascript

 
Output:
198

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

My Personal Notes arrow_drop_up