Software Development  >  Basics of C++  >  Code: Incremental Alphabets

Code: Incremental Alphabets - Basics of C++ - Software Development

Code: Incremental Alphabets | Basics of C++ - Software Development

C++ Program for printing 6 different Triangle/Half Pyramid Programs with Incremental Numbers

#include<iostream>


using namespace std;


void halfPyramidAlphabets1(int n) {

  char alphabet = 'a';

  for (int i = 1; i <= n; i++) {

    for (int j = 1; j <= i; j++) {

      cout << alphabet;

    }

    alphabet++;

    cout << endl;


  }

}

void halfPyramidAlphabets2(int n) {

  char alphabet = 'a';

  for (int i = n; i > 0; i--) {

    for (int j = 1; j <= i; j++) {

      cout << alphabet;

    }

    cout << endl;

    alphabet++;

  }

}


void halfPyramidAlphabets3(int n) {

  char alphabet = 'a';

  for (int i = 1; i <= n; i++) {

    for (int k = n - i; k > 0; k--)

      cout << " ";

    for (int j = 1; j <= i; j++) {

      cout << alphabet;

    }

    cout << endl;

    alphabet++;

  }

}


void halfPyramidAlphabets4(int n) {

  char alphabet = 'a';

  for (int i = n; i > 0; i--) {

    for (int k = n - i; k > 0; k--)

      cout << " ";

    for (int j = 1; j <= i; j++) {

      cout << alphabet;

    }

    cout << endl;

    alphabet++;

  }

}

void halfPyramidAlphabets5(int n) {


  for (int i = 1; i <= n; i++) {

    char alphabet = 'a';

    for (int j = 1; j <= i; j++) {

      cout << alphabet++;

    }

    cout << endl;

  }

}


void halfPyramidAlphabets6(int n) {

  char alphabet = 'a';

  for (int i = 1; i <= n; i++) {

    for (int j = 1; j <= i; j++) {

      cout << alphabet++;

    }

    cout << endl;

  }

}


int main() {

  int num;

  cout << "Enter number of levels of the pattern :" << endl;

  cin >> num;

  halfPyramidAlphabets1(num);

  cout << endl;

  halfPyramidAlphabets2(num);

  cout << endl;

  halfPyramidAlphabets3(num);

  cout << endl;

  halfPyramidAlphabets4(num);

  cout << endl;

  halfPyramidAlphabets5(num);

  cout << endl;

  halfPyramidAlphabets6(num);


  return 0;

}

The document Code: Incremental Alphabets | Basics of C++ - Software Development is a part of the Software Development Course Basics of C++.
All you need of Software Development at this link: Software Development
70 videos|45 docs|15 tests
70 videos|45 docs|15 tests
Download as PDF
Explore Courses for Software Development exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Download free EduRev App
Track your progress, build streaks, highlight & save important lessons and more!
Related Searches

Exam

,

Summary

,

Semester Notes

,

shortcuts and tricks

,

Extra Questions

,

study material

,

Code: Incremental Alphabets | Basics of C++ - Software Development

,

video lectures

,

Viva Questions

,

practice quizzes

,

past year papers

,

Important questions

,

pdf

,

MCQs

,

Sample Paper

,

Objective type Questions

,

mock tests for examination

,

Previous Year Questions with Solutions

,

Code: Incremental Alphabets | Basics of C++ - Software Development

,

Free

,

ppt

,

Code: Incremental Alphabets | Basics of C++ - Software Development

;