Program To Display The Half Pyramids, Numbers, Charac
Program To Display The Half Pyramids, Numbers, Charac
*
* *
* * *
* * * *
* * * * *
1.
2. #include <iostream>
3. using namespace std;
4. int main()
5. {
6.
int i,j,rows;
7.
8.
cin>>rows;
9.
for(i=1;i<=rows;++i)
10.
11.
for(j=1;j<=i;++j)
12.
13.
cout<<"* ";
14.
15.
cout<<"\n";
16.
17.
return 0;
18. }
C++ Program to print half pyramid as using numbers as shown in figure below.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1.
2. #include <iostream>
3. using namespace std;
4. int main()
5. {
6.
int i,j,rows;
7.
8.
cin>>rows;
9.
for(i=1;i<=rows;++i)
10.
11.
for(j=1;j<=i;++j)
12.
13.
cout<<j<<" ";
14.
15.
cout<<"\n";
16.
17.
return 0;
18. }
A
B B
C C C
D D D D
E E E E E
1.
2. #include <iostream>
3. using namespace std;
4. int main()
5. {
6.
int i,j;
7.
char input,temp='A';
8.
9.
cin>>input;
10.
for(i=1;i<=(input-'A'+1);++i)
11.
12.
for(j=1;j<=i;++j)
13.
cout<<temp<<" ";
14.
++temp;
15.
cout<<endl;
16.
17.
return 0;
18. }
*
*
*
*
* * * *
* * *
* *
*
*
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5.
int i,j,rows;
6.
7.
cin>>rows;
8.
for(i=rows;i>=1;--i)
9.
10.
for(j=1;j<=i;++j)
11.
12.
cout<<"* ";
13.
14.
cout<<"\n";
15.
16.
return 0;
17. }
C++ Program to print inverted half pyramid as using numbers as shown below.
1
1
1
1
2 3 4 5
2 3 4
2 3
2
1
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5.
int i,j,rows;
6.
7.
cin>>rows;
8.
for(i=rows;i>=1;--i)
9.
10.
for(j=1;j<=i;++j)
11.
12.
cout<<j<<" ";
13.
14.
cout<<"\n";
15.
16.
return 0;
17. }
*
* *
* * *
* * *
*
*
*
*
*
*
* *
* * *
* * * * *
1.
2. #include <iostream>
3. using namespace std;
4. int main()
5. {
6.
int i,space,rows,k;
7.
8.
cin>>rows;
9.
for(i=1;i<=rows;++i)
10.
11.
for(space=1;space<=rows-i;++space)
12.
13.
cout<<"
";
14.
15.
while(k!=2*i-1)
16.
17.
cout<<"* ";
18.
++k;
19.
20.
k=0;
21.
cout<<"\n";
22.
23.
return 0;
24. }
2
3 4
4 5 6
5 6 7
1
3
5
7
8
2
4 3
6 5 4
9 8 7 6 5
1.
2. #include <iostream>
3. using namespace std;
4. int main()
5. {
6.
int i,space,rows,k=0,count=0,count1=0;
7.
8.
cin>>rows;
9.
for(i=1;i<=rows;++i)
10.
11.
for(space=1;space<=rows-i;++space)
12.
13.
cout<<"
14.
++count;
";
15.
16.
while(k!=2*i-1)
17.
18.
if (count<=rows-1)
19.
20.
cout<<i+k<<" ";
21.
++count;
22.
23.
else
24.
25.
++count1;
26.
cout<<i+k-2*count1<<" ";
27.
28.
++k;
29.
30.
count1=count=k=0;
31.
cout<<"\n";
32.
33.
return 0;
34. }
*
*
*
*
*
* * * *
* * *
* *
*
1.
2. #include <iostream>
3. using namespace std;
4. int main()
5. {
6.
int rows,i,j,space;
7.
8.
cin>>rows;
9.
for(i=rows;i>=1;--i)
10.
11.
for(space=0;space<rows-i;++space)
12.
cout<<"
13.
";
for(j=i;j<=2*i-1;++j)
14.
cout<<"* ";
15.
for(j=0;j<i-1;++j)
16.
cout<<"* ";
17.
18.
cout<<endl;
}
19.
return 0;
20. }
1
1
3
10
1
2
6
1
1
10
1
1
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5.
int rows,coef=1,space,i,j;
6.
7.
cin>>rows;
8.
for(i=0;i<rows;i++)
9.
10.
for(space=1;space<=rows-i;space++)
11.
cout<<"
12.
for(j=0;j<=i;j++)
13.
";
14.
if (j==0||i==0)
15.
coef=1;
16.
17.
18.
else
coef=coef*(i-j+1)/j;
cout<<"
"<<coef;
19.
20.
cout<<endl;
21.
22. }
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5.
int rows,i,j,k=0;
6.
7.
cin>>rows;
8.
for(i=1;i<=rows;i++)
9.
10.
for(j=1;j<=i;++j)
11.
cout<<k+j<<" ";
12.
++k;
13.
cout<<endl;
14.
15.
return 0;
16. }
- See more at: http://www.programiz.com/article/c%2B%2B-programming-pattern#sthash.5Ruf6dFd.dpuf - See more
at: http://www.programiz.com/article/c%2B%2B-programming-pattern#sthash.5Ruf6dFd.dpuf - See more at: