Print Letter Pyramid - C++ Language Basics

C++ examples for Language Basics:Console

Description

Print Letter Pyramid

Demo Code

#include <iostream>
#include <string>

int main(int argc, const char* argv[]) {
    std::string base = "abcdefghijklmnopqrstuvwxyz";

    for (size_t i = 0, j = 1; i < 14; ++i, j += 2) {
        std::cout << std::string(14 - i, ' ');

        for (size_t k = 0, l = i; k < j; ++k) {
            std::cout << base[l];//from   w ww. java  2 s.  c  o m

            if (l == base.length()) std::cout << '{';

            ((k >= i) ? --l : ++l);
        }
        std::cout << std::endl;
    }

    return 0;
}

Result


Related Tutorials