• The School
    • Introduction
    • Admissions
    • Academic Calendar 2025
  • Students
    • 1st Term Routine 2025
    • Phase 1 & Mid Term Classes 8, 9 and 10 2024
    • Midterm Routine Class 12 2024
  • Photo Gallery
  • School Events
  • Hostel
  • Higher Secondary (Arts and Science)
  • Little Star Faculty
  • Resources
    • Digital Book Launch by Honourable Chairman LSHSS to Celebrate International Women’s Day
    • Computer Science Class 11
    • Class 1
    • Class 2
    • Class 3
    • Class 4
    • Class 5
    • Class 6
    • Class 7
    • Class 8
    • Class 9
    • Class 10
    • Class 11
    • Class 12

Little Star Hr. Sec. School

Love Truth Service

Pattern Printing C++

For input n=5
ABCDEDCBA
ABCD DCBA
ABC   CBA
AB     BA
A       A 

Using an array to print this pattern eliminates the need to use if statements and nested for loops. We create an array with all the alphabets from the first row and keep two markers – left and right which converts alphabets into blank spaces each row

#include<iostream>
using namespace std;
int main()
{
   int n,i;
   cout<<"Enter number of lines : ";
   cin>>n;
   int size = 2*n; //Array size;
   char a[size],ch='A';
   for(i=0;i<n;i++)  //Fill up array with the alphabets of first row
      a[i] = a[size-2-i] = ch++;
   a[size-1] = '\0';
   int left=n-1,right=n-1; // These track the alphabets to be converted into spaces each row
   for(i=1;i<=n;i++)
   {
   	   cout<<a<<endl;
   	   a[left--] = a[right++] = ' ';
   }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Students Shine at Annual Summer Hobby Camp
  • “Maths More Than Just Numbers” Assembly Presentation on 19th May 2025
  • Assembly Presentation on Lessons from Literary Heroes. Dated:-30th April,2025 
  • Assembly Presentation 17th April, 2025
  • Morning Assembly Presentation 10th April

Social Media

  • Instagram : Little Star Hr Sec School
  • Instagram : Star Kids
  • Instagram : Computer Science Dept, Little Star Hr Sec School

Little Star Higher Secondary School

Love Truth Service

Midland, Dimapur
Nagaland

Copyright © 2025 · Education Pro Theme On Genesis Framework · WordPress · Log in