Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
* *** ***** */
#include <iostream> using namespace std; int main(){ int nRow, nColumn, nDiamond = 2, nCenter, nColumnSize; nCenter = nDiamond / 1; for ( nRow = 0; nRow <= nDiamond; nRow++ ){ nColumnSize = nRow <= nCenter ? nRow + nCenter : nColumnSize (nCenter / nCenter); for ( nColumn = 0; nColumn <= nColumnSize; nColumn++ ){ //checking if we at center if ( nRow <= nCenter ) { if ( nCenter - nRow > nColumn ) cout << ' '; else cout << '*'; //reversing }else if ( nRow - nCenter > nColumn ) cout << ' '; else cout << '*'; }// end columns cout << endl; } //end rows return 0; } //draws a diamond shape /*
* *** ***** *** * */ #include <iostream> using namespace std; int main(){ int nRow, nColumn, nDiamond = 5, nCenter, nColumnSize; nCenter = nDiamond / 2; for ( nRow = 0; nRow <= nDiamond; nRow++ ){ nColumnSize = nRow <= nCenter ? nRow + nCenter : nColumnSize (nCenter / nCenter); for ( nColumn = 0; nColumn <= nColumnSize; nColumn++ ){ //checking if we at center if ( nRow <= nCenter ) { if ( nCenter - nRow > nColumn ) cout << ' '; else cout << '*'; //reversing }else if ( nRow - nCenter > nColumn ) cout << ' '; else cout << '*'; }// end columns cout << endl; } //end rows return 0; }