Below is a complete list of all the Number patterns.Outputs of all the codes have been put below the respective codes. This allows the user to view how the code works.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Code:
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,row;
clrscr();
cout<<"Enter the number of rows you want:\n";
cin>>row;
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
{
cout<<j;
}
cout<<"\n";
}
getch();
}
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Code: #include<iostream.h> #include<conio.h> void main() { int i,j,k,row; clrscr(); k=1; cout<<"Enter the no. of rows you want:\n"; cin>>row; for(i=1;i<=row;i++) { for(j=row;j>=1;j--) { if(j>i) cout<<" "; else cout<<k++; } cout<<"\n"; } getch(); }
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Code: #include<iostream.h> #include<conio.h> void main() { int i,j; clrscr(); cout<<"Enter the number of rows you want:\n"; cin>>row; for(i=1;i<=row;i++) { for(j=1;j<=i;j++) { cout<<i; } cout<<"\n"; } getch(); }
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
Code: #include<iostream.h> #include<conio.h> void main() { int i,j,k,row; clrscr(); cout<<"Enter the number of rows you want:\n"; cin>>row; for(i=1;i<=row;i++) { k = i; for(j=1;j<=i;j++) { cout<<k; k += row-j; } cout<<"\n"; } getch(); }
1
2 3
4 5 6
7 8 910
1112131415
Code: #include<iostream.h> #include<conio.h> void main() { int i,j,k,row; clrscr(); k=1; cout<<"Enter the no. of rows you want:\n"; cin>>row; for(i=1;i<=row;i++) { for(j=row;j>=1;j--) { if(j>i) cout<<" "; else cout<<k++; } cout<<"\n"; } getch(); }
1
0 1
0 0 1
0 0 0 1
0 0 0 0 1
Code: #include<iostream.h> #include<conio.h> void main() { int i,j,row; clrscr(); cout<<"Enter the number of rows you want:\n"; cin>>row; cout<<"\n"; for(i=1;i<=row;i++) { for(j=1;j<=i;j++) { cout<<j/i; } cout<<"\n"; } getch(); }
No comments:
Post a Comment