Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. Make a loop to print one line of stars
- // 2. Put it in another loop that tracks the spaces
- #include <iostream>
- using namespace std;
- int main() {
- int x=14;
- // for that case you can check if it is even and add 1 to the number
- if(x %2 ==0) {
- x+=1;
- }
- for(int j=0;j<x;j++){
- for(int i=0;i<x;i++){
- // we need to check for only half the list in one way then reverse for the second half
- int mid = x/2;
- // int diff = j < mid ? mid + j : mid +j;
- int difStart = j < mid ? mid - j : (j - mid);
- int difEnd = j < mid ? mid + j : (3*mid - j);
- if(i > difStart && i < difEnd){
- cout<<" ";
- } else {
- cout<<"*";
- }
- }
- cout <<'\n';
- }
- }
- // Phew finally it worked! now let us try increasing the number, try to give only odd number if you want to maintain the sy
- // the symmetry if i give even it is not in perfect symmetry, it is working fine now
- Please like share and subscribe!!!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement