Print reverse character bridge pattern

Here given code implementation process.

// C Program
// Print reverse character bridge pattern
#include <stdio.h>

void printBridgePattern(int n)
{
	if (n <= 0 || n > 26)
	{
		return;
	}
	// Loop controlling variables
	int i = 0;
	int j = 0;
	// Display given n
	printf("\nGiven n : %d \n\n", n);
	// iterating the loop through by size n
	for (i = 0; i < n; ++i)
	{
		// Print left side pattern
		for (j = 0; j < n - i; ++j)
		{
			printf("%c", ('A' + j));
		}
		for (j = 0; j < i + i; ++j)
		{
			// Include intermediate space
			printf(" ");
		}
		// Print right side pattern
		for (j = 'A' + (n - i - 1); j >= 'A'; --j)
		{
			printf("%c", j);
		}
		// Include new line
		printf("\n");
	}
}
int main(int argc, char const *argv[])
{
	// Test cases
	printBridgePattern(7);
	printBridgePattern(10);
	return 0;
}

input

Given n : 7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
// Java program for
// Print reverse character bridge pattern
public class BridgePattern
{
	public void printBridgePattern(int n)
	{
		if (n <= 0 || n > 26)
		{
			return;
		}
		// Loop controlling variables
		int i = 0;
		int j = 0;
		// Display given n
		System.out.print("\nGiven n : " + n + " \n\n");
		// iterating the loop through by size n
		for (i = 0; i < n; ++i)
		{
			// Print left side pattern
			for (j = 0; j < n - i; ++j)
			{
				System.out.print( (char)('A' + j));
			}
			for (j = 0; j < i + i; ++j)
			{
				// Include intermediate space
				System.out.print(" ");
			}
			// Print right side pattern
			for (j = 'A' + (n - i - 1); j >= 'A'; --j)
			{
				System.out.print((char) j);
			}
			// Include new line
			System.out.print("\n");
		}
	}
	public static void main(String[] args)
	{
		BridgePattern task = new BridgePattern();
		// Test cases
		task.printBridgePattern(7);
		task.printBridgePattern(10);
	}
}

input

Given n : 7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
// Include header file
#include <iostream>

using namespace std;
// C++ program for
// Print reverse character bridge pattern
class BridgePattern
{
	public: void printBridgePattern(int n)
	{
		if (n <= 0 || n > 26)
		{
			return;
		}
		// Loop controlling variables
		int i = 0;
		int j = 0;
		// Display given n
		cout << "\nGiven n : " << n << " \n\n";
		// iterating the loop through by size n
		for (i = 0; i < n; ++i)
		{
			// Print left side pattern
			for (j = 0; j < n - i; ++j)
			{
				cout << (char)('A' + j);
			}
			for (j = 0; j < i + i; ++j)
			{
				// Include intermediate space
				cout << " ";
			}
			// Print right side pattern
			for (j = 'A' + (n - i - 1); j >= 'A'; --j)
			{
				cout << (char) j;
			}
			// Include new line
			cout << "\n";
		}
	}
};
int main()
{
	BridgePattern *task = new BridgePattern();
	// Test cases
	task->printBridgePattern(7);
	task->printBridgePattern(10);
	return 0;
}

input

Given n : 7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
// Include namespace system
using System;
// Csharp program for
// Print reverse character bridge pattern
public class BridgePattern
{
	public void printBridgePattern(int n)
	{
		if (n <= 0 || n > 26)
		{
			return;
		}
		// Loop controlling variables
		int i = 0;
		int j = 0;
		// Display given n
		Console.Write("\nGiven n : " + n + " \n\n");
		// iterating the loop through by size n
		for (i = 0; i < n; ++i)
		{
			// Print left side pattern
			for (j = 0; j < n - i; ++j)
			{
				Console.Write((char)('A' + j));
			}
			for (j = 0; j < i + i; ++j)
			{
				// Include intermediate space
				Console.Write(" ");
			}
			// Print right side pattern
			for (j = 'A' + (n - i - 1); j >= 'A'; --j)
			{
				Console.Write((char) j);
			}
			// Include new line
			Console.Write("\n");
		}
	}
	public static void Main(String[] args)
	{
		BridgePattern task = new BridgePattern();
		// Test cases
		task.printBridgePattern(7);
		task.printBridgePattern(10);
	}
}

input

Given n : 7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
<?php
// Php program for
// Print reverse character bridge pattern
class BridgePattern
{
	public	function printBridgePattern($n)
	{
		if ($n <= 0 || $n > 26)
		{
			return;
		}
		// Loop controlling variables
		$i = 0;
		$j = 0;
		// Display given n
		echo("\nGiven n : ".$n.
			" \n\n");
		// iterating the loop through by size n
		for ($i = 0; $i < $n; ++$i)
		{
			// Print left side pattern
			for ($j = 0; $j < $n - $i; ++$j)
			{
				echo(chr((ord('A') + $j)));
			}
			for ($j = 0; $j < $i + $i; ++$j)
			{
				// Include intermediate space
				echo(" ");
			}
			// Print right side pattern
			for ($j = ord('A') + ($n - $i - 1); $j >= ord('A'); --$j)
			{
				echo(chr($j));
			}
			// Include new line
			echo("\n");
		}
	}
}

function main()
{
	$task = new BridgePattern();
	// Test cases
	$task->printBridgePattern(7);
	$task->printBridgePattern(10);
}
main();

input

Given n : 7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
// Node JS program for
// Print reverse character bridge pattern
class BridgePattern
{
	printBridgePattern(n)
	{
		if (n <= 0 || n > 26)
		{
			return;
		}
		// Loop controlling variables
		var i = 0;
		var j = 0;
		// Display given n
		process.stdout.write("\nGiven n : " + n + " \n\n");
		// iterating the loop through by size n
		for (i = 0; i < n; ++i)
		{
			// Print left side pattern
			for (j = 0; j < n - i; ++j)
			{
				process.stdout.write(
                  String.fromCharCode(('A'.charCodeAt(0) + j)));
			}
			for (j = 0; j < i + i; ++j)
			{
				// Include intermediate space
				process.stdout.write(" ");
			}
			// Print right side pattern
			for (j = 'A'.charCodeAt(0) + (n - i - 1); 
                 j >= 'A'.charCodeAt(0); 
                 --j)
			{
				process.stdout.write(String.fromCharCode(j));
			}
			// Include new line
			process.stdout.write("\n");
		}
	}
}

function main()
{
	var task = new BridgePattern();
	// Test cases
	task.printBridgePattern(7);
	task.printBridgePattern(10);
}
main();

input

Given n : 7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
#  Python 3 program for
#  Print reverse character bridge pattern
class BridgePattern :
	def printBridgePattern(self, n) :
		if (n <= 0 or n > 26) :
			return
		
		#  Loop controlling variables
		i = 0
		j = 0
		#  Display given n
		print("\nGiven n : ", n ," \n")
		#  iterating the loop through by size n
		while (i < n) :
			#  Print left side pattern
			j = 0
			while (j < n - i) :
				print(chr((ord('A') + j)), end = "")
				j += 1
			
			j = 0
			while (j < i + i) :
				#  Include intermediate space
				print(" ", end = "")
				j += 1
			
			#  Print right side pattern
			j = ord('A') + (n - i - 1)
			while (j >= ord('A')) :
				print(chr(j), end = "")
				j -= 1
			
			#  Include new line
			print(end = "\n")
			i += 1
		
	

def main() :
	task = BridgePattern()
	#  Test cases
	task.printBridgePattern(7)
	task.printBridgePattern(10)

if __name__ == "__main__": main()

input

Given n :  7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n :  10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
#  Ruby program for
#  Print reverse character bridge pattern
class BridgePattern 
	def printBridgePattern(n) 
		if (n <= 0 || n > 26) 
			return
		end

		#  Loop controlling variables
		i = 0
		j = 0
		#  Display given n
		print("\nGiven n : ", n ," \n\n")
		#  iterating the loop through by size n
		while (i < n) 
			#  Print left side pattern
			j = 0
			while (j < n - i) 
				print((('A'.ord + j)).chr)
				j += 1
			end

			j = 0
			while (j < i + i) 
				#  Include intermediate space
				print(" ")
				j += 1
			end

			#  Print right side pattern
			j = 'A'.ord + (n - i - 1)
			while (j >= 'A'.ord) 
				print((j).chr)
				j -= 1
			end

			#  Include new line
			print("\n")
			i += 1
		end

	end

end

def main() 
	task = BridgePattern.new()
	#  Test cases
	task.printBridgePattern(7)
	task.printBridgePattern(10)
end

main()

input

Given n : 7 

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10 

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
// Scala program for
// Print reverse character bridge pattern
class BridgePattern()
{
	def printBridgePattern(n: Int): Unit = {
		if (n <= 0 || n > 26)
		{
			return;
		}
		// Loop controlling variables
		var i: Int = 0;
		var j: Int = 0;
		// Display given n
		print("\nGiven n : " + n + " \n\n");
		// iterating the loop through by size n
		while (i < n)
		{
			// Print left side pattern
			j = 0;
			while (j < n - i)
			{
				print(('A'.toInt + j).toChar);
				j += 1;
			}
			j = 0;
			while (j < i + i)
			{
				// Include intermediate space
				print(" ");
				j += 1;
			}
			// Print right side pattern
			j = 'A'.toInt + (n - i - 1);
			while (j >= 'A'.toInt)
			{
				print(j.toChar);
				j -= 1;
			}
			// Include new line
			print("\n");
			i += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: BridgePattern = new BridgePattern();
		// Test cases
		task.printBridgePattern(7);
		task.printBridgePattern(10);
	}
}

input

Given n : 7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
// Swift 4 program for
// Print reverse character bridge pattern
class BridgePattern
{
	func printBridgePattern(_ n: Int)
	{
		if (n <= 0 || n > 26)
		{
			return;
		}
		// Loop controlling variables
		var i = 0;
		var j = 0;
		// Display given n
		print("\nGiven n : ", n ," \n");
		// iterating the loop through by size n
		while (i < n)
		{
			// Print left side pattern
			j = 0;
			while (j < n - i)
			{
				print(Character(UnicodeScalar(65 + j)!), terminator: "");
				j += 1;
			}
			j = 0;
			while (j < i + i)
			{
				// Include intermediate space
				print(" ", terminator: "");
				j += 1;
			}
			// Print right side pattern
			j = 65 + (n - i - 1);
			while (j >= 65)
			{
				print(Character(UnicodeScalar(j)!), terminator: "");
				j -= 1;
			}
			// Include new line
			print(terminator: "\n");
			i += 1;
		}
	}
}
func main()
{
	let task = BridgePattern();
	// Test cases
	task.printBridgePattern(7);
	task.printBridgePattern(10);
}
main();

input

Given n :  7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n :  10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A
// Kotlin program for
// Print reverse character bridge pattern
class BridgePattern
{
	fun printBridgePattern(n: Int): Unit
	{
		if (n <= 0 || n > 26)
		{
			return;
		}
		// Loop controlling variables
		var i: Int = 0;
		var j: Int = 0;
		// Display given n
		print("\nGiven n : " + n + " \n\n");
		// iterating the loop through by size n
		while (i < n)
		{
			// Print left side pattern
			
			while (j < n - i)
			{
				print(('A'.toInt() + j).toChar());
				j += 1;
			}
			j = 0;
			while (j < i + i)
			{
				// Include intermediate space
				print(" ");
				j += 1;
			}
			// Print right side pattern
			j = 'A'.toInt() + (n - i - 1);
			while (j >= 'A'.toInt())
			{
				print(j.toChar());
				j -= 1;
			}
			// Include new line
			print("\n");
			i += 1;
          	j = 0;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: BridgePattern = BridgePattern();
	// Test cases
	task.printBridgePattern(7);
	task.printBridgePattern(10);
}

input

Given n : 7

ABCDEFGGFEDCBA
ABCDEF  FEDCBA
ABCDE    EDCBA
ABCD      DCBA
ABC        CBA
AB          BA
A            A

Given n : 10

ABCDEFGHIJJIHGFEDCBA
ABCDEFGHI  IHGFEDCBA
ABCDEFGH    HGFEDCBA
ABCDEFG      GFEDCBA
ABCDEF        FEDCBA
ABCDE          EDCBA
ABCD            DCBA
ABC              CBA
AB                BA
A                  A

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