Skip to main content

Sum of cubes of n even natural numbers

The sum of cubes of n even natural numbers means the sum of the cubes of the first n even natural numbers.

To derive a formula using 2×(n×(n+1))² for the sum of cubes of n even natural numbers, we can use the following steps:

  1. The first even natural number is 2, the second is 4, the third is 6, and so on.
  2. We can express each even natural number as 2k, where k is a natural number starting from 1. For example, the first even natural number (2) can be expressed as 21, the second even natural number (4) can be expressed as 22, and so on.
  3. The sum of the cubes of the first n even natural numbers can be expressed as: (21)^3 + (22)^3 + (23)^3 + ... + (2n)^3.
  4. We can simplify this expression as: 8*(1^3 + 2^3 + 3^3 + ... + n^3).
  5. We know that the sum of cubes of the first n natural numbers can be expressed as: (n*(n+1)/2)^2. Therefore, the sum of cubes of the first n even natural numbers can be expressed as: 8*(n*(n+1)/2)^2.
  6. Simplifying this expression further, we get: 2*(n*(n+1))^2.

Thus, the formula for the sum of cubes of n even natural numbers using 2×(n×(n+1))² is 2*(n*(n+1))^2.

Code Solution

// C Program
// Sum of cubes of n even natural numbers
#include <stdio.h>

void findSunOfCube(int n)
{
	if (n <= 0)
	{
		return;
	}
	// Calculate sum of cube of n natural number
	// Formula : 2×(n×(n+1))²
	double sum = 2 *((n *(n + 1)) *(n *(n + 1)));
	// Display calculated result
	printf("\n %lf", sum);
}
int main()
{
	int n = 3;
	/*
	    n = 3
	*/
	findSunOfCube(n);
	return 0;
}

Output

 288.000000
// Java program for
// Sum of cubes of n even natural numbers
public class Sum
{
    public void findSunOfCube(int n)
    {
        if (n <= 0)
        {
            return;
        }
        // Calculate sum of cube of n natural number
        // Formula : 2×(n×(n+1))²
        double sum = 2 * ((n * (n + 1)) * (n * (n + 1)));
        // Display calculated result
        System.out.print("\n " + sum );
    }
    public static void main(String[] args)
    {
        Sum task = new Sum();

        int n = 3;
        /*
            n = 3
        */
        task.findSunOfCube(n);
    }
}

Output

 288.0
// Include header file
#include <iostream>

using namespace std;
// C++ program for
// Sum of cubes of n even natural numbers
class Sum
{
	public: void findSunOfCube(int n)
	{
		if (n <= 0)
		{
			return;
		}
		// Calculate sum of cube of n natural number
		// Formula : 2×(n×(n+1))²
		double sum = 2 *((n *(n + 1)) *(n *(n + 1)));
		// Display calculated result
		cout << "\n " << sum;
	}
};
int main()
{
	Sum *task = new Sum();
	int n = 3;
	/*
	    n = 3
	*/
	task->findSunOfCube(n);
	return 0;
}

Output

 288
// Include namespace system
using System;
// Csharp program for
// Sum of cubes of n even natural numbers
public class Sum
{
	public void findSunOfCube(int n)
	{
		if (n <= 0)
		{
			return;
		}
		// Calculate sum of cube of n natural number
		// Formula : 2×(n×(n+1))²
		double sum = 2 * ((n * (n + 1)) * (n * (n + 1)));
		// Display calculated result
		Console.Write("\n " + sum);
	}
	public static void Main(String[] args)
	{
		Sum task = new Sum();
		int n = 3;
		/*
		    n = 3
		*/
		task.findSunOfCube(n);
	}
}

Output

 288
package main
import "fmt"
// Go program for
// Sum of cubes of n even natural numbers
type Sum struct {}
func getSum() * Sum {
	var me *Sum = &Sum {}
	return me
}
func(this Sum) findSunOfCube(n int) {
	if n <= 0 {
		return
	}
	// Calculate sum of cube of n natural number
	// Formula : 2×(n×(n+1))²
	sum := 2 * ((n * (n + 1)) * (n * (n + 1)))
	// Display calculated result
	fmt.Print("\n ", sum)
}
func main() {
	var task * Sum = getSum()
	var n int = 3
	/*
	    n = 3
	*/
	task.findSunOfCube(n)
}

Output

 288
<?php
// Php program for
// Sum of cubes of n even natural numbers
class Sum
{
	public	function findSunOfCube($n)
	{
		if ($n <= 0)
		{
			return;
		}
		// Calculate sum of cube of n natural number
		// Formula : 2×(n×(n+1))²
		$sum = 2 * (($n * ($n + 1)) * ($n * ($n + 1)));
		// Display calculated result
		echo("\n ".$sum);
	}
}

function main()
{
	$task = new Sum();
	$n = 3;
	/*
	    n = 3
	*/
	$task->findSunOfCube($n);
}
main();

Output

 288
// Node JS program for
// Sum of cubes of n even natural numbers
class Sum
{
	findSunOfCube(n)
	{
		if (n <= 0)
		{
			return;
		}
		// Calculate sum of cube of n natural number
		// Formula : 2×(n×(n+1))²
		var sum = 2 * ((n * (n + 1)) * (n * (n + 1)));
		// Display calculated result
		process.stdout.write("\n " + sum);
	}
}

function main()
{
	var task = new Sum();
	var n = 3;
	/*
	    n = 3
	*/
	task.findSunOfCube(n);
}
main();

Output

 288
#  Python 3 program for
#  Sum of cubes of n even natural numbers
class Sum :
	def findSunOfCube(self, n) :
		if (n <= 0) :
			return
		
		#  Calculate sum of cube of n natural number
		#  Formula : 2×(n×(n+1))²
		sum = 2 * ((n * (n + 1)) * (n * (n + 1)))
		#  Display calculated result
		print("\n ", sum, end = "")
	

def main() :
	task = Sum()
	n = 3
	#    n = 3
	task.findSunOfCube(n)

if __name__ == "__main__": main()

Output

  288
#  Ruby program for
#  Sum of cubes of n even natural numbers
class Sum 
	def findSunOfCube(n) 
		if (n <= 0) 
			return
		end

		#  Calculate sum of cube of n natural number
		#  Formula : 2×(n×(n+1))²
		sum = 2 * ((n * (n + 1)) * (n * (n + 1)))
		#  Display calculated result
		print("\n ", sum)
	end

end

def main() 
	task = Sum.new()
	n = 3
	#    n = 3
	task.findSunOfCube(n)
end

main()

Output

 288
// Scala program for
// Sum of cubes of n even natural numbers
class Sum()
{
	def findSunOfCube(n: Int): Unit = {
		if (n <= 0)
		{
			return;
		}
		// Calculate sum of cube of n natural number
		// Formula : 2×(n×(n+1))²
		var sum: Double = 2 * ((n * (n + 1)) * (n * (n + 1)));
		// Display calculated result
		print("\n " + sum);
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Sum = new Sum();
		var n: Int = 3;
		/*
		    n = 3
		*/
		task.findSunOfCube(n);
	}
}

Output

 288.0
// Swift 4 program for
// Sum of cubes of n even natural numbers
class Sum
{
	func findSunOfCube(_ n: Int)
	{
		if (n <= 0)
		{
			return;
		}
		// Calculate sum of cube of n natural number
		// Formula : 2×(n×(n+1))²
		let sum: Int = 2 * ((n * (n + 1)) * (n * (n + 1)));
		// Display calculated result
		print("\n ", sum, terminator: "");
	}
}
func main()
{
	let task: Sum = Sum();
	let n: Int = 3;
	/*
	    n = 3
	*/
	task.findSunOfCube(n);
}
main();

Output

  288
// Kotlin program for
// Sum of cubes of n even natural numbers
class Sum
{
	fun findSunOfCube(n: Int): Unit
	{
		if (n <= 0)
		{
			return;
		}
		// Calculate sum of cube of n natural number
		// Formula : 2×(n×(n+1))²
		val sum = 2 * ((n * (n + 1)) * (n * (n + 1)));
		// Display calculated result
		print("\n " + sum);
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Sum = Sum();
	val n: Int = 3;
	/*
	    n = 3
	*/
	task.findSunOfCube(n);
}

Output

 288




Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment