Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //box pattern
- #include<stdio.h>
- #include<conio.h>
- #include<iostream.h>
- int main()
- {
- int no,i,j,a,b;
- clrscr();
- cout<<"\n Enter the number: ";
- cin>>no;
- cout<<"\n\n===============CUBE========================="<<endl;
- //full cube
- for(i=0;i<(no*2);i++) //loop=1
- {
- //half part
- for(j=0;j<(no*2);j++) //loop=2
- {
- if(j<no)
- {
- if(j<=i && i<no)
- {
- cout<<j+1<<" ";
- }
- else if(j>i && i<no)
- {
- cout<<i+1<<" ";
- }
- }
- if(j>no)
- {
- b=(no*2)-j;
- if(b<=i && i<no)
- {
- cout<<b<<" ";
- }
- else if(b>i && i<no)
- {
- cout<<i+1<<" ";
- }
- }
- }
- //second half cube
- a=(no*2)-i; //for i=1 and then i++;
- for(j=0;j<(no*2);j++) //loop=3
- {
- if(j<no)
- {
- if(j<a && i>no)
- {
- cout<<j+1<<" ";
- }
- else if(j>=a &&i>no)
- {
- cout<<a<<" ";
- }
- }
- if(j>no)
- {
- b=(no*2)-j;
- if(b<=a && a<no)
- {
- cout<<b<<" ";
- }
- else if(b>a && a<no)
- {
- cout<<a<<" ";
- }
- }
- }
- if(i!=no) //avoid blank line of middle
- {
- cout<<endl;
- }
- }
- getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment