Showing posts with label Patterns.. Show all posts
Showing posts with label Patterns.. Show all posts

Saturday, December 5, 2020

Simple pattern 6 in C++ language.

 Simple pattern 6 in C++ language.



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
        1    2   3
   1   2    3   4


solution:


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

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;
}

Simple pattern 4 in C++.

Simple pattern 4 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

2   3

4   5    6

7    8    9   10


solution:


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

 

Simple pattern3 in C++.

Simple pattern 3 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

2   1

3    2    1

4    3    2   1


solution:


#include<iostream>

using namespace std;

int main()

{

int n;

cin>>n;

for(int i=1;i<=n;i++)

{

int x = i;

for(int j=1;j<=i;j++)

{

cout<<x--<<" ";

}

cout<<endl;

}

return 0;

}  

Simple pattern2 in C++.

Simple pattern2 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

2   2

3    3    3

4    4    4   4 


solution:


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

Friday, December 4, 2020

Simple pattern1 in C++.

 Simple pattern1 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

1    2    3

1    2    3    4

1    2    3    4    5


solution:


#include<iostream>

using namespace std;

int main()

{

int n;

cin>>n;

for(int i=1;i<=n;i++)

{

for(int j=1;j<=i;j++)

{

cout<<j<<" ";

}

cout<<endl;

}

return 0;

}


If you want to learn c++ in depth then do visit: learn c++ in depth.