Skip to main content

Posts

Showing posts from 2015

C++ Diamond Pattern

C++ program to print the diamond pattern using '#' symbols. In this program two for loops are used to print the pattern. The first loop prints the upper part to the diamond ( triangle part ). The second for loop prints the lower part of the diamond (an inverted triangle ) . By combining both of the triangles an diamond pattern structure is formed. PROGRAM CODE: #include<iostream> using namespace std; int main() { int i,j,k=1,s=6,l; for(i=0;i<5;i++,k-=2,s-=1) { for(l=s-1;l>=0;l--) cout<<' '; for(j=k;j<0;j++) cout<<"#"; cout<<endl; } k = 9; s = 0; for(i=0;i<5;i++,k-=2,s+=1) { for(l=s;l>=0;l--) cout<<' '; for(j=k;j>0;j--) cout<<"#"; cout<<endl; } return 0; } OUTPUT:            #         # # #      # # # # #    # # # # # # # # #