EmSAT Achieve Exam  >  EmSAT Achieve Notes  >  C++ for EmSAT Achieve  >  Code: Simple Triangle/ Half Pyramid

Code: Simple Triangle/ Half Pyramid | C++ for EmSAT Achieve PDF Download

Code: Simple Triangle/ Half Pyramid | C++ for EmSAT Achieve

C++ Program for printing 4 different Triangle/Half Pyramid Programs

#include <iostream>

using namespace std;


void halfPyramidPattern1(int n)

{

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

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

            cout << "*";

        }

        cout << endl;

    }

}

void halfPyramidPattern2(int n)

{

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

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

            cout << "*";

        }

        cout << endl;

    }

}

void halfPyramidPattern3(int n)

{

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

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

            cout << " ";

        }

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

            cout << "*";

        }

        cout << endl;

    }

}


void halfPyramidPattern4(int n)

{

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

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

            cout << " ";

        }

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

            cout << "*";

        }

        cout << endl;

    }

}


int main()

{

    int num;

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

    cin >> num;

    halfPyramidPattern1(num);

    cout << endl;

    halfPyramidPattern2(num);

    cout << endl;

    halfPyramidPattern3(num);

    cout << endl;

    halfPyramidPattern4(num);


    return 0;

}

The document Code: Simple Triangle/ Half Pyramid | C++ for EmSAT Achieve is a part of the EmSAT Achieve Course C++ for EmSAT Achieve.
All you need of EmSAT Achieve at this link: EmSAT Achieve
70 videos|45 docs|15 tests

Top Courses for EmSAT Achieve

70 videos|45 docs|15 tests
Download as PDF
Explore Courses for EmSAT Achieve exam

Top Courses for EmSAT Achieve

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
Related Searches

video lectures

,

Viva Questions

,

Code: Simple Triangle/ Half Pyramid | C++ for EmSAT Achieve

,

Extra Questions

,

Objective type Questions

,

practice quizzes

,

Important questions

,

study material

,

Previous Year Questions with Solutions

,

Semester Notes

,

Free

,

MCQs

,

pdf

,

mock tests for examination

,

past year papers

,

shortcuts and tricks

,

Code: Simple Triangle/ Half Pyramid | C++ for EmSAT Achieve

,

Summary

,

Code: Simple Triangle/ Half Pyramid | C++ for EmSAT Achieve

,

ppt

,

Sample Paper

,

Exam

;