c++ - Printing diamond of stars -


i printing diamond of stars code compiling , running printing half of diamond......anyone please help.

below have mentioned code. cannot understand problem why system executing first half , not other half of diamond.

#include<iostream> using namespace std; int main() {     int n,i=0,j;     cin>>n;      while(i<=(n/2))     {     j=0;     while(j<(n/2)-i){         cout<<" ";         j=j+1;      }     j=0;     while(j<i+1){         cout<<"*";         j=j+1;     }     j=0;     while(j<=i-1){         cout<<"*";         j=j+1;     }     cout<<"\n";     i=i+1;     }  while(i<=(n/2))        {         j=0;         while(j<(n/2)-i)         {             cout<<" ";             j=j+1;          }         j=0;         while(j<i)             {             cout<<"*";             j=j+1;             }         j=0;         while(j<i-1){             cout<<"*";             j++;         }         cout<<"\n";         i--;       }  return 0; } 

you using same iterator (i) in both while() loops. either use different iterator in second loop, or reset it.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -