A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C++ to print a pyramid of digits as shown below for n number of lines
Q:

Write a program in C++ to print a pyramid of digits as shown below for n number of lines

0

Write a program in C++ to print a pyramid of digits as shown below for n number of lines

Sample Output:

 Display the pattern like pyramid using digits:                        
---------------------------------------------------                    
 Input the number of rows: 5                                           
    1                                                                  
   232                                                                 
  34543                                                                
 4567654                                                               
567898765

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

int main()
{
    int i, j, spc, n;
    cout << "\n\n Display the pattern like pyramid using digits:\n";
    cout << "---------------------------------------------------\n";
    cout << " Input the number of rows: ";
    cin >> n;
    for (i = 1; i <= n; i++) 
    {
        spc = n - i;
        while (spc-- > 0)
            cout << " ";
        for (j = i; j < 2 * i - 1; j++)
            cout << j;
        for (j = 2 * i - 1; j > i - 1; j--)
            cout << j;
        cout << endl;
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now