Aniket_Goku

BOX PATTER IN C++

Jul 16th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. //box pattern
  2.  
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #include<iostream.h>
  6. int main()
  7. {
  8.     int no,i,j,a,b;
  9.     clrscr();
  10.     cout<<"\n Enter the number: ";
  11.     cin>>no;
  12.     cout<<"\n\n===============CUBE========================="<<endl;
  13.     //full cube
  14.     for(i=0;i<(no*2);i++)       //loop=1
  15.     {
  16. //half part
  17.         for(j=0;j<(no*2);j++)   //loop=2
  18.         {
  19.  
  20.             if(j<no)
  21.             {
  22.                 if(j<=i && i<no)
  23.                 {
  24.                     cout<<j+1<<" ";
  25.                 }
  26.                 else if(j>i && i<no)
  27.                 {
  28.                     cout<<i+1<<" ";
  29.                 }
  30.             }
  31.             if(j>no)
  32.             {
  33.                 b=(no*2)-j;
  34.                 if(b<=i && i<no)
  35.                 {
  36.                     cout<<b<<" ";
  37.                 }
  38.                 else if(b>i && i<no)
  39.                 {
  40.                     cout<<i+1<<" ";
  41.                 }
  42.             }
  43.         }
  44. //second half cube
  45.         a=(no*2)-i;           //for i=1 and then i++;
  46.         for(j=0;j<(no*2);j++)         //loop=3
  47.         {
  48.             if(j<no)
  49.             {
  50.                 if(j<a && i>no)
  51.                 {
  52.                     cout<<j+1<<" ";
  53.                 }
  54.                 else if(j>=a &&i>no)
  55.                 {
  56.                     cout<<a<<" ";
  57.                 }
  58.             }
  59.             if(j>no)
  60.             {
  61.                 b=(no*2)-j;
  62.                 if(b<=a && a<no)
  63.                 {
  64.                     cout<<b<<" ";
  65.                 }
  66.                 else if(b>a && a<no)
  67.                 {
  68.                     cout<<a<<" ";
  69.                 }
  70.             }
  71.         }
  72.         if(i!=no) //avoid blank line of middle
  73.         {
  74.             cout<<endl;
  75.         }
  76.     }
  77.     getch();
  78.     return 0;
  79. }
Add Comment
Please, Sign In to add comment