Q:

Print Reverse Triangle Bridge Pattern for Characters in C++

belongs to collection: C++ programs on various topics

0

Reverse Triangle Bridge Pattern looks like as:

Print Reverse Triangle Bridge Pattern for Characters in C++

To print this pattern, we can use ASCII codes of the corresponding characters to print them. Our program accepts the input of largest alphabet value in the pattern (e.g., C=3, E=5). Above Pattern shows the constant width/spacing in both the reverse triangles. By using if, else if and else statement within the nesting of for loop gives the desired result.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program

#include<iostream>
using namespace std;

int main()
{  
	int i,j,n;
	cout<<"Enter Largest Alphabet Value(e.g C=3):";
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=65;j<64+(2*n);j++)
		{ 
			if(j>=(64+n)+i)
				cout<<(char)((64+n)-(j%(64+n)));
			else if(j<=(64+n)-i)
				cout<<(char)j;
			else
				cout<<" ";
		}
		cout<<endl;
	}

	return 0;
}

Output

C++ program to print reverse triangle bridge pattern for characters

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ programs on various topics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Sort an array in ascending order using sort() func... >>
<< C++ program to print the maximum possible time usi...