Program to print reverse character bridge pattern Last Updated : 20 Feb, 2023 Comments Improve Suggest changes Like Article Like Report For a given value N, denoting the number of Charters starting from the A, print reverse character bridge pattern.Examples : Input : n = 5 Output : ABCDEDCBA ABCD DCBA ABC CBA AB BA A A Input : n = 8 Output : ABCDEFGHGFEDCBA ABCDEFG GFEDCBA ABCDEF FEDCBA ABCDE EDCBA ABCD DCBA ABC CBA AB BA A A Recommended: Please solve it on PRACTICE first, before moving on to the solution.For a given value N, reflect the number of characters taking part in the pattern, starting from A. For N = 5, Participating character would be A B C D E.By using a nested for loop we would compute the logic. Where the outer loop of 'i' would range from 0 to N and the inner loop of 'j' would range from 65(Start) to 64 + 2*N.Under which we would check the required condition for the pattern design. For all the values of j which are less than ((64+n)+ i) it would print the (char)((64 + n)-( j % (64+n))) and for all the values of j <= ((64+n) -i) it would print (char)j. C++ // CPP program to print reverse character bridge pattern #include <iostream> using namespace std; // Function to print pattern void ReverseCharBridge(int n) { for (int i = 0; i < n; i++) { for (int j = 'A'; j < 'A' + (2 * n) - 1; j++) { if (j >= ('A' + n - 1) + i) cout << (char)(('A' + n - 1) - (j % ('A' + n - 1))); else if (j <= ('A' + n - 1) - i) cout << (char)j; else cout << " "; } cout << endl; } } // Driver Code int main() { int n = 6; ReverseCharBridge(n); return 0; } Java // Java program to print reverse // character bridge pattern import java.io.*; class GFG { // Function to print pattern static void ReverseCharBridge(int n) { for (int i = 0; i < n; i++) { for (int j = 'A'; j < 'A' + (2 * n) - 1; j++) { if (j >= ('A' + n - 1) + i) System.out.print((char)(('A' + n - 1) - (j % ('A' + n - 1)))); else if (j <= ('A' + n - 1) - i) System.out.print((char)j); else System.out.print(" "); } System.out.println(); } } // Driver Code public static void main(String args[]) { int n = 6; ReverseCharBridge(n); } } /*This code is contributed by Nikita Tiwari.*/ Python3 # Python3 code to print reverse # character bridge pattern # Function to print pattern def ReverseCharBridge( n ): for i in range( n ): for j in range( ord('A'), ord('A') + (2 * n) - 1): if j >= (ord( 'A' ) + n - 1) + i: print(chr((ord('A') + n - 1) - (j % (ord('A') + n - 1))), end = '') elif j <= (ord('A') + n - 1) - i: print(chr(j), end = '') else: print(end = " ") print("\n", end = '') # Driver Code n = 6 ReverseCharBridge(n) # This code is contributed by "Sharad_Bhardwaj". C# // C# program to print reverse // character bridge pattern using System; class GFG { // Function to print pattern static void ReverseCharBridge(int n) { for (int i = 0; i < n; i++) { for (int j = 'A'; j < 'A' + (2 * n) - 1; j++) { if (j >= ('A' + n - 1) + i) Console.Write((char)(('A' + n - 1) - (j % ('A' + n - 1)))); else if (j <= ('A' + n - 1) - i) Console.Write((char)j); else Console.Write(" "); } Console.WriteLine(); } } // Driver Code public static void Main() { int n = 6; ReverseCharBridge(n); } } // This code is contributed by vt_m. PHP <?php // PHP program to print reverse // character bridge pattern // Function to print pattern function ReverseCharBridge($n) { //Ascii of A is 65 for ($i = 0; $i < $n; $i++) { for ($j = 65; $j < 65 + (2 * $n) - 1; $j++) { if ($j >= (65 + $n - 1) + $i) echo chr((65 + $n - 1) - ($j % (65 + $n - 1))); else if ($j <= (65 + $n - 1) - $i) echo chr($j); else echo " "; } echo "\n"; } } // Driver Code $n = 6; ReverseCharBridge($n); // This code is contributed by mits ?> JavaScript <script> // Javascript program to print reverse character bridge pattern // Function to print pattern function ReverseCharBridge(n) { for (let i = 0; i < n; i++) { for (let j = 65; j < 65 + (2 * n) - 1; j++) { if (j >= (65 + n - 1) + i) document.write(String.fromCharCode((65 + n - 1) - (j % (65 + n - 1)))); else if (j <= (65 + n - 1) - i) document.write(String.fromCharCode(j)); else document.write(" "); } document.write("\n"); } } // Driver Code let n = 6; ReverseCharBridge(n); // This code is contributed by Samim Hossain Mondal. </script> OutputABCDEFEDCBA ABCDE EDCBA ABCD DCBA ABC CBA AB BA A A Time Complexity: O(n2) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to print reverse character bridge pattern GeeksforGeeks Improve Article Tags : Misc Algorithms Analysis of Algorithms Mathematical Technical Scripter C++ Programs DSA Basic Coding Problems pattern-printing +5 More Practice Tags : AlgorithmsMathematicalMiscpattern-printing Similar Reads C++ Program To Print Character Pattern Here we will build a C++ Program To Print Character patterns using 2 Approaches i.e. Using for loopUsing while loop Printing 1 character pattern in C++ using different approaches. 1. Using for loop Input: rows = 5 Output: A B B C C C D D D D E E E E E Approach 1: Assign any character to one variable 5 min read Program to print Step Pattern The program must accept a string S and an integer N as the input. The program must print the desired pattern as shown below: Examples: Input: string = "abcdefghijk", n = 3 Output: a *b **c *d e *f **g *h i *j **k Explanation: Here N is 3. The highest possible height of the string pattern must be 3. 7 min read C++ Program To Print Reverse Floyd's Triangle Floydâs triangle is a triangle with first natural numbers. Task is to print reverse of Floydâs triangle.Examples: Input: 4 Output: 10 9 8 7 6 5 4 3 2 1 Input: 5 Output: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 C++ // C++ program to print reverse // of Floyd's triangle #include <bits/stdc++.h> using 1 min read Reverse alternate k characters in a string Given a string str and an integer k, the task is to reverse alternate k characters of the given string. If characters present are less than k, leave them as it is.Examples: Input: str = "geeksforgeeks", k = 3 Output: eegksfgroeeksInput: str = "abcde", k = 2 Output: bacde Approach: The idea is to fir 9 min read C++ Program To Print Reverse of a String Using Recursion Write a recursive function to print the reverse of a given string. Code: C++ // C++ program to reverse a string using recursion #include <bits/stdc++.h> using namespace std; /* Function to print reverse of the passed string */ void reverse(string str) { if(str.size() == 0) { return; } reverse 2 min read Like