Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Practice Mathematical Algorithm
  • Mathematical Algorithms
  • Pythagorean Triplet
  • Fibonacci Number
  • Euclidean Algorithm
  • LCM of Array
  • GCD of Array
  • Binomial Coefficient
  • Catalan Numbers
  • Sieve of Eratosthenes
  • Euler Totient Function
  • Modular Exponentiation
  • Modular Multiplicative Inverse
  • Stein's Algorithm
  • Juggler Sequence
  • Chinese Remainder Theorem
  • Quiz on Fibonacci Numbers
Open In App
Next Article:
Program to print reverse character bridge pattern
Next article icon

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> 

Output
ABCDEFEDCBA  ABCDE EDCBA  ABCD   DCBA  ABC     CBA  AB       BA  A         A

Time Complexity: O(n2)

Auxiliary Space: O(1)


Next Article
Program to print reverse character bridge pattern
https://media.geeksforgeeks.org/auth/avatar.png
GeeksforGeeks
Improve
Article Tags :
  • Misc
  • Algorithms
  • Analysis of Algorithms
  • Mathematical
  • Technical Scripter
  • C++ Programs
  • DSA
  • Basic Coding Problems
  • pattern-printing
Practice Tags :
  • Algorithms
  • Mathematical
  • Misc
  • pattern-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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences