Saturday, December 5, 2020

Simple pattern 5 in C++.

Simple pattern 5 in C++.


In this blog we will learn to print simple pattern in C++.It is very simple pattern printing.It is fundamental part of programming.


We are going to print below pattern:


Question: Write a program in c++ that take input from user and print following pattern till user input?


1

1 2

2 3 4

4 5 6 7

7 8 9 10 11

11 12 13 14 15 16


solution:


#include<iostream>
using namespace std;
int main()
{
int n,now=1,prev=1;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
prev = now;
cout<<now++<<" ";
}
now = prev;
cout<<endl;
}
return 0;
}

Share this

0 Comment to "Simple pattern 5 in C++."

Post a Comment

If you have any doubts then let me know.