C++ Program To Print Number Without Reassigning Last Updated : 25 Aug, 2022 Suggest changes Share 1 Likes Like Report Here, we will build a C++ program to print the number pattern without Reassigning using 2 approaches i.e. Using for loopUsing while loop1. Using for loop Input: n = 5 Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 The first for loop is used to iterate the number of rows and the second for loop is used to repeat the number of columns. Then print the number and increment the number to print the next number. C++ // C++ program to print number pattern // without re assigning using for loop #include <iostream> using namespace std; int main() { int rows, columns, number = 1, n = 5; // first for loop is used to identify number of rows for (rows = 0; rows <= n; rows++) { // second for loop is used to identify number of // columns and here the values will be changed // according to the first for loop for (columns = 0; columns < rows; columns++) { // printing number pattern based on the number // of columns cout << number << " "; // incrementing number at each column to print // the next number number++; } // print the next line for each row cout << "\n"; } return 0; } Output1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2. Using while loop Input: n = 5 Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 The while loops check the condition until the condition is false. If the condition is true then it enters into the loop and executes the statements. C++ // C++ program to print number without // reassigning patterns using while loop #include <iostream> using namespace std; int main() { int rows = 1, columns = 0, n = 5; // 1 value is assigned to the number // helpful to print the number pattern int number = 1; // while loops check the condition and repeat // the loop until the condition is false while (rows <= n) { while (columns <= rows - 1) { // printing number to get required pattern cout << number << " "; // incrementing columns value columns++; // incrementing number value to print the next // number number++; } columns = 0; // incrementing rows value rows++; cout << endl; } return 0; } Output1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 L laxmigangarajula03 Follow 1 Article Tags : C++ Programs C++ C Pattern Programs Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like