C++ gurus and learners, we program ourselves :P all work is CC licensed

Wednesday, November 6

Special Diamonds Continued -- Usman Sherry

21:29 By

(Continued From Special Diamonds Part 1) Part 2; Here will use 2 loops inside one loop so that it is easy to print shape in less loops and coding; It is simple because the loop we used for triangle in first page is going to be repeated in this loop only we will change the size alignment of shapes upside down;


int i,j,k,rows,size1,size2;
cin<<rows;
size1      [as described before you have to choose sequence of shapes so ]
size2      [there are two options size1=1 and size2=rows /// or size2=rows and size1=1]
do
{           j=size1;
do          
{
cout<<”required character”;
j--;
} while (j < size);
size1 ?? ;                                              //here you define corresponding proceeding size
                k=size2;
do          
{
cout<<”required character”;
k--;
} while (j < size);
size2 ?? ;                                              //here you define corresponding proceeding size
}
while(i<rows);

I hope you have got the idea
do{                                                         //the main loop
                do{                                         //corresponding first shape
}while
do{                                         //corresponding second shape
}while
}while
And in case of diamond you have to detect central row and print same size pyramid upside and then same size pyramid downside
To detect central row รจ              total rows / 2 = central row -1                     //do not use this in code
i.e. central row=(total rows/2 +1);            //use this in code to detect central row
in this way you can print first part then print single row of size of central row then print second part so that the both main loops will have same size and almost same coding;
first main loop                                                  
central row
last main loop

6 comments :

  1. Oy satianas ho gya iska yara.. next time me khud hi kr lun ga jesy bhi hua

    ReplyDelete
  2. :D please sir, word ke bajaye visual studio use kerna, word saar icheezain kharab ker deta hai :P

    ReplyDelete
  3. yaar he sent me a word file, us sey copy paste mai saar aproblem hua :P

    ReplyDelete