Efficiently multiply a number by 7

Here given code implementation process.

// C program
// Efficiently multiply a number by 7
#include <stdio.h>

// Perform multiplication by seven
void multiplyBy7(int n)
{
	// Equivalent to  n *7
	printf("\n %d X 7 = %d", n, ((n << 3) - n));
}
int main(int argc, char
	const *argv[])
{
	// Test Cases
	multiplyBy7(-3);
	multiplyBy7(10);
	multiplyBy7(5);
	multiplyBy7(13);
	return 0;
}

Output

 -3 X 7 = -21
 10 X 7 = 70
 5 X 7 = 35
 13 X 7 = 91
// Java program
// Efficiently multiply a number by 7
public class Multiply
{
	// Perform multiplication by seven
	public void multiplyBy7(int n)
	{
		// Same as num * 7
		System.out.print("\n" + n + " X 7 = " + ((n << 3) - n));
	}
	public static void main(String[] args)
	{
		Multiply task = new Multiply();
		// Test Cases
		task.multiplyBy7(-3);
		task.multiplyBy7(10);
		task.multiplyBy7(5);
		task.multiplyBy7(13);
	}
}

Output

-3 X 7 = -21
10 X 7 = 70
5 X 7 = 35
13 X 7 = 91
// Include header file
#include <iostream>

using namespace std;
// C++ program
// Efficiently multiply a number by 7
class Multiply
{
	public:
		// Perform multiplication by seven
		void multiplyBy7(int n)
		{
			// Same as num *7
			cout << "\n" << n << " X 7 = " << ((n << 3) - n);
		}
};
int main()
{
	Multiply task = Multiply();
	// Test Cases
	task.multiplyBy7(-3);
	task.multiplyBy7(10);
	task.multiplyBy7(5);
	task.multiplyBy7(13);
	return 0;
}

Output

-3 X 7 = -21
10 X 7 = 70
5 X 7 = 35
13 X 7 = 91
// Include namespace system
using System;
// C# program
// Efficiently multiply a number by 7
public class Multiply
{
	// Perform multiplication by seven
	public void multiplyBy7(int n)
	{
		// Same as num * 7
		Console.Write("\n" + n + " X 7 = " + ((n << 3) - n));
	}
	public static void Main(String[] args)
	{
		Multiply task = new Multiply();
		// Test Cases
		task.multiplyBy7(-3);
		task.multiplyBy7(10);
		task.multiplyBy7(5);
		task.multiplyBy7(13);
	}
}

Output

-3 X 7 = -21
10 X 7 = 70
5 X 7 = 35
13 X 7 = 91
<?php
// Php program
// Efficiently multiply a number by 7
class Multiply
{
	// Perform multiplication by seven
	public	function multiplyBy7($n)
	{
		// Same as num * 7
		echo "\n". $n ." X 7 = ". (($n << 3) - $n);
	}
}

function main()
{
	$task = new Multiply();
	$task->multiplyBy7(-3);
	$task->multiplyBy7(10);
	$task->multiplyBy7(5);
	$task->multiplyBy7(13);
}
main();

Output

-3 X 7 = -21
10 X 7 = 70
5 X 7 = 35
13 X 7 = 91
// Node Js program
// Efficiently multiply a number by 7
class Multiply
{
	// Perform multiplication by seven
	multiplyBy7(n)
	{
		// Same as num * 7
		process.stdout.write("\n" + n + " X 7 = " + ((n << 3) - n));
	}
}

function main()
{
	var task = new Multiply();
	// Test Cases
	task.multiplyBy7(-3);
	task.multiplyBy7(10);
	task.multiplyBy7(5);
	task.multiplyBy7(13);
}
main();

Output

-3 X 7 = -21
10 X 7 = 70
5 X 7 = 35
13 X 7 = 91
#  Python 3 program
#  Efficiently multiply a number by 7
class Multiply :
	#  Perform multiplication by seven
	def multiplyBy7(self, n) :
		#  Same as num * 7
		print("\n", n ," X 7 = ", ((n << 3) - n), end = "")
	

def main() :
	task = Multiply()
	#  Test Cases
	task.multiplyBy7(-3)
	task.multiplyBy7(10)
	task.multiplyBy7(5)
	task.multiplyBy7(13)

if __name__ == "__main__": main()

Output

 -3  X 7 =  -21
 10  X 7 =  70
 5  X 7 =  35
 13  X 7 =  91
#  Ruby program
#  Efficiently multiply a number by 7
class Multiply 
	#  Perform multiplication by seven
	def multiplyBy7(n) 
		#  Same as num * 7
		print("\n", n ," X 7 = ", ((n << 3) - n))
	end

end

def main() 
	task = Multiply.new()
	#  Test Cases
	task.multiplyBy7(-3)
	task.multiplyBy7(10)
	task.multiplyBy7(5)
	task.multiplyBy7(13)
end

main()

Output

-3 X 7 = -21
10 X 7 = 70
5 X 7 = 35
13 X 7 = 91
// Scala program
// Efficiently multiply a number by 7
class Multiply
{
	// Perform multiplication by seven
	def multiplyBy7(n: Int): Unit = {
		// Same as num * 7
		print("\n" + n + " X 7 = " + ((n << 3) - n));
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Multiply = new Multiply();
		// Test Cases
		task.multiplyBy7(-3);
		task.multiplyBy7(10);
		task.multiplyBy7(5);
		task.multiplyBy7(13);
	}
}

Output

-3 X 7 = -21
10 X 7 = 70
5 X 7 = 35
13 X 7 = 91
// Swift 4 program
// Efficiently multiply a number by 7
class Multiply
{
	// Perform multiplication by seven
	func multiplyBy7(_ n: Int)
	{
		// Same as num * 7
		print( n ," X 7 = ", ((n << 3) - n));
	}
}
func main()
{
	let task: Multiply = Multiply();
	// Test Cases
	task.multiplyBy7(-3);
	task.multiplyBy7(10);
	task.multiplyBy7(5);
	task.multiplyBy7(13);
}
main();

Output

-3  X 7 =  -21
10  X 7 =  70
5  X 7 =  35
13  X 7 =  91
// Kotlin program
// Efficiently multiply a number by 7
class Multiply
{
	// Perform multiplication by seven
	fun multiplyBy7(n: Int): Unit
	{
		// Same as num * 7
		print("\n" + n + " X 7 = " + ((n shl 3) - n));
	}
}
fun main(args: Array < String > ): Unit
{
	var task: Multiply = Multiply();
	// Test Cases
	task.multiplyBy7(-3);
	task.multiplyBy7(10);
	task.multiplyBy7(5);
	task.multiplyBy7(13);
}

Output

-3 X 7 = -21
10 X 7 = 70
5 X 7 = 35
13 X 7 = 91

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







© 2021, kalkicode.com, All rights reserved