Add one to given number

Here given code implementation process.

// C Program
// Add one to given  number 
#include <stdio.h>

// Increase given number by one
void incrementByOne(int num)
{
    // Display given number
    printf("\n Number : %d",num);
    // Display increment value by one
    printf("\n After Add One : %d", -(~num));
}
int main()
{
    // Test Cases
    // 17 (10001) => (10010)
    incrementByOne(17);
    // 9 (1001)  =>  (1010)
    incrementByOne(9);
    // 1 (1)     => (10)
    incrementByOne(1);
    // 7 (111)   => (1000)
    incrementByOne(7);
    // 10 (1010) => (1011)
    incrementByOne(10);
    // -1 (11111111111) => (0)
    incrementByOne(-1);
    return 0;
}

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0
/*
  Java Program
  Add one to given  number 
*/
public class Incrementation
{
	// Increase given number by one
	public void incrementByOne(int num)
	{
		// Display given number
		System.out.print("\n Number : " + num);
		// Display increment value by one
		System.out.print("\n After Add One : " + -(~num));
	}
	public static void main(String[] args)
	{
		Incrementation task = new Incrementation();
		// Test Cases
		// 17 (10001) => (10010)
		task.incrementByOne(17);
		// 9 (1001)  =>  (1010)
		task.incrementByOne(9);
		// 1 (1)     => (10)
		task.incrementByOne(1);
		// 7 (111)   => (1000)
		task.incrementByOne(7);
		// 10 (1010) => (1011)
		task.incrementByOne(10);
		// -1 (11111111111) => (0)
		task.incrementByOne(-1);
	}
}

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0
// Include header file
#include <iostream>
using namespace std;

/*
  C++ Program
  Add one to given  number 
*/

class Incrementation
{
	public:
		// Increase given number by one
		void incrementByOne(int num)
		{
			// Display given number
			cout << "\n Number : " << num;
			// Display increment value by one
			cout << "\n After Add One : " << -(~num);
		}
};
int main()
{
	Incrementation task = Incrementation();
	// Test Cases
	// 17 (10001) => (10010)
	task.incrementByOne(17);
	// 9 (1001)  =>  (1010)
	task.incrementByOne(9);
	// 1 (1)     => (10)
	task.incrementByOne(1);
	// 7 (111)   => (1000)
	task.incrementByOne(7);
	// 10 (1010) => (1011)
	task.incrementByOne(10);
	// -1 (11111111111) => (0)
	task.incrementByOne(-1);
	return 0;
}

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0
// Include namespace system
using System;
/*
  C# Program
  Add one to given  number 
*/
public class Incrementation
{
	// Increase given number by one
	public void incrementByOne(int num)
	{
		// Display given number
		Console.Write("\n Number : " + num);
		// Display increment value by one
		Console.Write("\n After Add One : " + -(~num));
	}
	public static void Main(String[] args)
	{
		Incrementation task = new Incrementation();
		// Test Cases
		// 17 (10001) => (10010)
		task.incrementByOne(17);
		// 9 (1001)  =>  (1010)
		task.incrementByOne(9);
		// 1 (1)     => (10)
		task.incrementByOne(1);
		// 7 (111)   => (1000)
		task.incrementByOne(7);
		// 10 (1010) => (1011)
		task.incrementByOne(10);
		// -1 (11111111111) => (0)
		task.incrementByOne(-1);
	}
}

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0
<?php
/*
  Php Program
  Add one to given  number 
*/
class Incrementation
{
	// Increase given number by one
	public	function incrementByOne($num)
	{
		// Display given number
		echo "\n Number : ". $num;
		// Display increment value by one
		echo "\n After Add One : ". -(~$num);
	}
}

function main()
{
	$task = new Incrementation();
	// Test Cases
	// 17 (10001) => (10010)
	$task->incrementByOne(17);
	// 9 (1001)  =>  (1010)
	$task->incrementByOne(9);
	// 1 (1)     => (10)
	$task->incrementByOne(1);
	// 7 (111)   => (1000)
	$task->incrementByOne(7);
	// 10 (1010) => (1011)
	$task->incrementByOne(10);
	// -1 (11111111111) => (0)
	$task->incrementByOne(-1);
}
main();

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0
/*
  Node Js Program
  Add one to given  number 
*/
class Incrementation
{
	// Increase given number by one
	incrementByOne(num)
	{
		// Display given number
		process.stdout.write("\n Number : " + num);
		// Display increment value by one
		process.stdout.write("\n After Add One : " + (-(~num)));
	}
}

function main()
{
	var task = new Incrementation();
	// Test Cases
	// 17 (10001) => (10010)
	task.incrementByOne(17);
	// 9 (1001)  =>  (1010)
	task.incrementByOne(9);
	// 1 (1)     => (10)
	task.incrementByOne(1);
	// 7 (111)   => (1000)
	task.incrementByOne(7);
	// 10 (1010) => (1011)
	task.incrementByOne(10);
	// -1 (11111111111) => (0)
	task.incrementByOne(-1);
}
main();

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0
#   Python 3 Program
#   Add one to given  number 

class Incrementation :
	#  Increase given number by one
	def incrementByOne(self, num) :
		#  Display given number
		print("\n Number : ", num, end = "")
		#  Display increment value by one
		print("\n After Add One : ", -(~num), end = "")
	

def main() :
	task = Incrementation()
	#  Test Cases
	#  17 (10001) => (10010)
	task.incrementByOne(17)
	#  9 (1001)  =>  (1010)
	task.incrementByOne(9)
	#  1 (1)     => (10)
	task.incrementByOne(1)
	#  7 (111)   => (1000)
	task.incrementByOne(7)
	#  10 (1010) => (1011)
	task.incrementByOne(10)
	#  -1 (11111111111) => (0)
	task.incrementByOne(-1)

if __name__ == "__main__": main()

Output

 Number :  17
 After Add One :  18
 Number :  9
 After Add One :  10
 Number :  1
 After Add One :  2
 Number :  7
 After Add One :  8
 Number :  10
 After Add One :  11
 Number :  -1
 After Add One :  0
#   Ruby Program
#   Add one to given  number 

class Incrementation 
	#  Increase given number by one
	def incrementByOne(num) 
		#  Display given number
		print("\n Number : ", num)
		#  Display increment value by one
		print("\n After Add One : ", -(~num))
	end

end

def main() 
	task = Incrementation.new()
	#  Test Cases
	#  17 (10001) => (10010)
	task.incrementByOne(17)
	#  9 (1001)  =>  (1010)
	task.incrementByOne(9)
	#  1 (1)     => (10)
	task.incrementByOne(1)
	#  7 (111)   => (1000)
	task.incrementByOne(7)
	#  10 (1010) => (1011)
	task.incrementByOne(10)
	#  -1 (11111111111) => (0)
	task.incrementByOne(-1)
end

main()

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0
/*
  Scala Program
  Add one to given  number 
*/
class Incrementation
{
	// Increase given number by one
	def incrementByOne(num: Int): Unit = {
		// Display given number
		print("\n Number : " + num);
		// Display increment value by one
		print("\n After Add One : " + -(~num));
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Incrementation = new Incrementation();
		// Test Cases
		// 17 (10001) => (10010)
		task.incrementByOne(17);
		// 9 (1001)  =>  (1010)
		task.incrementByOne(9);
		// 1 (1)     => (10)
		task.incrementByOne(1);
		// 7 (111)   => (1000)
		task.incrementByOne(7);
		// 10 (1010) => (1011)
		task.incrementByOne(10);
		// -1 (11111111111) => (0)
		task.incrementByOne(-1);
	}
}

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0
/*
  Swift 4 Program
  Add one to given  number 
*/
class Incrementation
{
	// Increase given number by one
	func incrementByOne(_ num: Int)
	{
		// Display given number
		print("\n Number : ", num, terminator: "");
		// Display increment value by one
		print("\n After Add One : ", -(~num), terminator: "");
	}
}
func main()
{
	let task: Incrementation = Incrementation();
	// Test Cases
	// 17 (10001) => (10010)
	task.incrementByOne(17);
	// 9 (1001)  =>  (1010)
	task.incrementByOne(9);
	// 1 (1)     => (10)
	task.incrementByOne(1);
	// 7 (111)   => (1000)
	task.incrementByOne(7);
	// 10 (1010) => (1011)
	task.incrementByOne(10);
	// -1 (11111111111) => (0)
	task.incrementByOne(-1);
}
main();

Output

 Number :  17
 After Add One :  18
 Number :  9
 After Add One :  10
 Number :  1
 After Add One :  2
 Number :  7
 After Add One :  8
 Number :  10
 After Add One :  11
 Number :  -1
 After Add One :  0
/*
  Kotlin Program
  Add one to given  number 
*/
class Incrementation
{
	// Increase given number by one
	fun incrementByOne(num: Int): Unit
	{
		// Display given number
		print("\n Number : " + num);
		// Display increment value by one
		print("\n After Add One : " + -(num.inv()));
	}
}
fun main(args: Array < String > ): Unit
{
	var task: Incrementation = Incrementation();
	// Test Cases
	// 17 (10001) => (10010)
	task.incrementByOne(17);
	// 9 (1001)  =>  (1010)
	task.incrementByOne(9);
	// 1 (1)     => (10)
	task.incrementByOne(1);
	// 7 (111)   => (1000)
	task.incrementByOne(7);
	// 10 (1010) => (1011)
	task.incrementByOne(10);
	// -1 (11111111111) => (0)
	task.incrementByOne(-1);
}

Output

 Number : 17
 After Add One : 18
 Number : 9
 After Add One : 10
 Number : 1
 After Add One : 2
 Number : 7
 After Add One : 8
 Number : 10
 After Add One : 11
 Number : -1
 After Add One : 0


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