+ 2
it's a rhombus (the first asterisk is misplaced in the question) well a good way to learn is try posting ur attempted solution and let others correct it rather than giving the answer itself hint: use a loop for spaces and for stars
16th Aug 2018, 7:08 PM
Harsh
+ 1
space+stars+space=total column count 2+1+2=5, row 0 1+3+1=5, row 1 0+5+0=5, row 2 1+3+1=5, row 3 2+1+2=5, row 4 n is 5 variable numSpaces initialized to 2 numStars in each iteration = n-2*numSpaces after each iteration, numSpaces-- (if it's -ive, just multiply by -1) int n=5; int numSpaces = 2; /* n/5? */ for (int row=0; row<n; row++) { for(int m=0;m<numSpaces;m++) { cout<<" "; } etc, can u try writing the rest, it's painful to type on mobile lol :p
16th Aug 2018, 7:40 PM
Harsh
+ 1
your welcome
16th Aug 2018, 7:50 PM
Harsh
+ 1
about ur question of nested loops, maybe some clever string manipulation and all might be able to achieve it, I don't know, will have to rattle too much brains :p
16th Aug 2018, 7:55 PM
Harsh
+ 1
lol u r over-studying :p ah but extra studying never hurts, as long as u hv done the actual studying first :) best of luck for ur test tmrow
16th Aug 2018, 8:00 PM
Harsh
0
I just googled, and they used 2 iterations, one where no of stars is increasing, and then another separate one where it's decreasing
16th Aug 2018, 7:42 PM
Harsh
0
I think this should work... #include <iostream> using namespace std; int main(){ int n=5; int numSpaces=n/2; for(int row=0; row<n; row++) { int positiveSpaces = (numSpaces<0)? numSpaces*(-1): numSpaces; for(int m=0; m<positiveSpaces; m++) cout<<" "; for(int m=0; m<n-2*positiveSpaces; m++) cout<<"*"; numSpaces--; cout<<"\n"; }//For row }//main
16th Aug 2018, 7:49 PM
Harsh