This C++ code prints a diamond pattern with letters. It takes an input limit n and prints the pattern using nested for loops. The first for loop iterates from i=1 to n and prints the top half of the diamond. The second for loop prints spaces for the left side of the diamond, and the third and fourth for loops print the letters in each row. After printing the top half, the second for loop iterates from i=1 to n-1 and prints the bottom half of the diamond. The third for loop prints spaces for the left side of the diamond, and the fourth and fifth for loops print the letters in each row.
#include<iostream> using namespace std; int main() { int i,j,n; cout<<"\n Enter the limit:"; cin>>n; for(i=1;i<=n;i++) { for(j=1;j<=n-i;j++) { cout<<" "; } for(j=1;j<i;j++) { cout<<char(j+64); } for(j=i;j>=1;j--) { cout<<char(j+64); } cout<<"\n"; } for(i=1;i<n;i++) { for(j=1;j<=i;j++) { cout<<" "; } for(j=1;j<n-i;j++) { cout<<char(j+64); } for(j=n-i;j>=1;j--) { cout<<char(j+64); } cout<<"\n"; } return 0; }To download raw file Click Here
         A
        ABA
       ABCBA
      ABCDCBA
     ABCDEDCBA
    ABCDEFEDCBA
   ABCDEFGFEDCBA
  ABCDEFGHGFEDCBA
 ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
 ABCDEFGHIHGFEDCBA
  ABCDEFGHGFEDCBA
   ABCDEFGFEDCBA
    ABCDEFEDCBA
     ABCDEDCBA
      ABCDCBA
       ABCBA
        ABA
         A
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions