English

Write a program in C++ to generate and print the following pattern: 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 - Computer Science 1

Advertisements
Advertisements

Question

Write a program in C++ to generate and print the following pattern:

1

2  2 

3  3  3

4  4  4  4

5  5  5  5  5

Code Writing
Advertisements

Solution

#include<iostream.h>
#include<conio.h>
void main()
{
    int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            cout<<i<<" ";
        }
        cout<<"\n";
    }
    getch();
}
shaalaa.com
  Is there an error in this question or solution?
2023-2024 (July) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×