-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNumberPattern.cpp
More file actions
50 lines (47 loc) · 818 Bytes
/
NumberPattern.cpp
File metadata and controls
50 lines (47 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*Print the Number pattern
1
23
345
4567
*/
#include<iostream>
using namespace std;
int main(){
//First Approach
cout<<"---First Approach---\n";
int totalrows = 4;
int row = 1;
while(row <= totalrows){
int col = 1;
int num = row;
while(col <= totalrows + row -1){
if(col <= (totalrows - row)){
cout<<" ";
}else if(col <= totalrows){
cout<<num;
num = num+1;
}
col++;
}
row++;
cout<<"\n";
}
//Second Approach
cout<<"\n----Second Approach----\n";
int totalrows_2 = 4;
int row_2 = 1;
while(row_2 <= totalrows_2){
int spaces = 1;
while(spaces < totalrows_2 - row_2){
cout<<" ";
spaces++;
}
int col_2 = 1;
while(col_2 <= row_2){
cout<<(row_2+col_2-1);
col_2++;
}
row_2++;
cout<<"\n";
}
}