Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Print a pattern like highest numbers of columns appear in first row

C++ For Loop: Exercise-50 with Solution

Write a program in C++ to print a pattern like highest numbers of columns appear in first row.

Pictorial Presentation:

C++ Exercises: Print a pattern like highest numbers of columns appear in first row

Sample Solution:-

C++ Code :

#include <iostream>
using namespace std;

int main()
{
    int i, j, n;
    cout << "\n\n Display the pattern like highest numbers of columns appear in first row:\n";
    cout << "------------------------------------------------------------------------------\n";
    cout << " Input the number of rows: ";
    cin >> n;
    for (i = 1; i <= n;) 
    {
        cout << i;
        for (j = i + 1; j <= n;) 
        {
            cout << j;
            j = j + 1;
        }
        cout << endl;
        i = i + 1;
    }
}

Sample Output:

 Display the pattern like highest numbers of columns appear in first row:                                                                    
------------------------------------------------------------------------------                                                                
 Input the number of rows: 5                                           
12345                                                                  
2345                                                                   
345                                                                    
45                                                                     
5 

Flowchart:

Flowchart: Print a pattern like heighest numbers of columns appear in first row

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C++ to print a pyramid of digits as shown below for n number of lines.
Next: Write a program in C++ to display the pattern using digits with right justified and the highest columns appears in first row.

What is the difficulty level of this exercise?