Advertisement
sourav8256

c++ patterns

Feb 14th, 2023
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6. // 1. Make a loop to print one line of stars
  7. // 2. Put it in another loop that tracks the spaces
  8.  
  9.  
  10. #include <iostream>
  11.  
  12. using namespace std;
  13.  
  14. int main() {
  15.     int x=14;
  16.    
  17.     // for that case you can check if it is even and add 1 to the number
  18.    
  19.     if(x %2 ==0) {
  20.         x+=1;
  21.     }
  22.     for(int j=0;j<x;j++){
  23.         for(int i=0;i<x;i++){
  24.            
  25.     // we need to check for only half the list in one way then reverse for the second half
  26.     int mid = x/2;
  27.     // int diff = j < mid ? mid + j : mid +j;
  28.     int difStart = j < mid ? mid - j : (j - mid);
  29.     int difEnd = j < mid ? mid + j : (3*mid - j);
  30.    
  31.             if(i > difStart  &&  i < difEnd){
  32.                 cout<<" ";
  33.             } else {
  34.                 cout<<"*";
  35.             }
  36.         }
  37.        
  38.        
  39.         cout <<'\n';
  40.     }
  41.    
  42.    
  43.  
  44. }
  45.  
  46. // Phew finally it worked! now let us try increasing the number, try to give only odd number if you want to maintain the sy
  47. // the symmetry if i give even it is not in perfect symmetry, it is working fine now
  48.  
  49.  
  50.  
  51. Please like share and subscribe!!!!!
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement