EmSAT Achieve Exam  >  EmSAT Achieve Notes  >  C++ for EmSAT Achieve  >  Code: Incremental Numbers

Code: Incremental Numbers | C++ for EmSAT Achieve PDF Download

Code: Incremental Numbers | C++ for EmSAT Achieve

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

#include<iostream>

using namespace std;

void halfPyramidNumbers1(int n) {

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

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

      cout << i;

    }

    cout << endl;

  }

}

void halfPyramidNumbers2(int n) {

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

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

      cout << (n - i + 1);

    }

    cout << endl;

  }

}

void halfPyramidNumbers3(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 << i;

    }

    cout << endl;

  }

}

void halfPyramidNumbers4(int n) {

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

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

      cout << " ";

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

      cout << (n - i + 1);

    }

    cout << endl;

  }

}

void halfPyramidNumbers5(int n) {

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

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

      cout << j;

    }

    cout << endl;

  }

}

void halfPyramidNumbers6(int n) {

  int x = 1;

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

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

      cout << x++ << " ";

    }

    cout << endl;

  }

}

int main() {

  int num;

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

  cin >> num;

  halfPyramidNumbers1(num);

  cout << endl;

  halfPyramidNumbers2(num);

  cout << endl;

  halfPyramidNumbers3(num);

  cout << endl;

  halfPyramidNumbers4(num);

  cout << endl;

  halfPyramidNumbers5(num);

  cout << endl;

  halfPyramidNumbers6(num);

  return 0;

}

The document Code: Incremental Numbers | 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

Free

,

MCQs

,

study material

,

pdf

,

Important questions

,

Code: Incremental Numbers | C++ for EmSAT Achieve

,

Previous Year Questions with Solutions

,

Extra Questions

,

shortcuts and tricks

,

past year papers

,

ppt

,

Semester Notes

,

Objective type Questions

,

Code: Incremental Numbers | C++ for EmSAT Achieve

,

Code: Incremental Numbers | C++ for EmSAT Achieve

,

video lectures

,

Summary

,

practice quizzes

,

Sample Paper

,

Viva Questions

,

mock tests for examination

,

Exam

;