0% found this document useful (0 votes)
13 views5 pages

Pattern Codes in C++

The document contains multiple C++ code snippets that generate various patterns based on user input. Patterns include alphabetic sequences, numeric sequences, Floyd's triangle, and pyramid shapes. Each code snippet is accompanied by a description of the expected output when a specific number is entered.

Uploaded by

tejassasane7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Pattern Codes in C++

The document contains multiple C++ code snippets that generate various patterns based on user input. Patterns include alphabetic sequences, numeric sequences, Floyd's triangle, and pyramid shapes. Each code snippet is accompanied by a description of the expected output when a specific number is entered.

Uploaded by

tejassasane7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Pattern:-

A
B B
C C C
D D D D
-----------
#include <iostream>
using namespace std;

int main(){

int num;
cout <<"enter number:- ";
cin >>num;
char ch='A';
for(int i=0; i<num; i++){
for(int j=0; j<i+1; j++){
cout <<ch<<" ";
}

cout <<endl;
ch=ch+1;
}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------------------------

Pattern:-
enter number:- 4
1
1 2
1 2 3
1 2 3 4
-----------
#include <iostream>
using namespace std;

int main(){

int num;
cout <<"enter number:- ";
cin >>num;

for(int i=0; i<num; i++){

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


cout <<j<<" ";

cout <<endl;
}
return 0;
}

-----------------------------------------------------------------------------------
-------------------------------------------------------
Pattern:-
enter number:- 4
1
2 1
3 2 1
4 3 2 1
-----------
#include <iostream>
using namespace std;

int main(){

int num;
cout <<"enter number:- ";
cin >>num;

for(int i=0; i<num; i++){

for(int j=i+1; j>0; j--){


cout <<j<<" ";

cout <<endl;
}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------------------------

Pattern:- Floyds Triangle


enter number:- 4
1
2 3
4 5 6
7 8 9 10
----------------------
#include <iostream>
using namespace std;

int main(){

int num;
cout <<"enter number:- ";
cin >>num;
int n=1;
for(int i=0; i<num; i++){

for(int j=0; j<=i; j++){


cout <<n<<" ";
n=n+1;

cout <<endl;
}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------------------------

Pattern:-
Enter the number:- 4
A
B A
C B A
D C B A
--------------
#include <iostream>
using namespace std;

int main(){

int num;
cout <<"Enter the number:- ";
cin >> num;

for (int i = 0; i < num; i++){


for (char j = 'A' + i; j >= 'A'; j--){
cout << j << " ";
}
cout << endl;
}
return 0;
}

-----------------------------------------------------------------------------------
------------------------------------------------------

Pattern:-
Enter the number:- 4
1111
222
33
4
-------------
#include <iostream>
using namespace std;

int main(){

int num;
cout <<"Enter the number:- ";
cin >> num;

for (int i=0; i<num; i++){


//print space
for (int j=0; j<i; j++){
cout <<" ";
}
//print numbers
for(int j=0; j<num-i; j++){
cout <<i+1;
}
cout << endl;
}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------------------------

Pattern:-
Enter the number:- 4
AAAA
BBB
CC
D
------------------
#include <iostream>
using namespace std;

int main(){

int num;
cout <<"Enter the number:- ";
cin >> num;
char ch='A';
for (int i=0; i<num; i++){
//print space
for (int j=0; j<i; j++){
cout <<" ";
}
//print numbers
for(int j=0; j<num-i; j++){
cout <<ch;
}
ch=ch+1;
cout << endl;
}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------------------------

Pattern:- Pyramid pattern


Enter the number:- 5
1
121
12321
1234321
123454321
-----------------------
#include <iostream>
using namespace std;

int main(){

int num;
cout <<"Enter the number:- ";
cin >> num;

for (int i=0; i<num; i++){


//print space
for (int j=0; j<num-i-1; j++){
cout <<" ";
}
//print numbers set1
for(int j=1; j<=i+1; j++){
cout <<j;
}

//print number set 2


for(int j=i; j>=1; j--){
cout <<j;
}

cout << endl;


}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------------------------

You might also like