Sei sulla pagina 1di 3

//display /* 00 to 99 Nested Loops */ #include<iostream> using namespace std; int main() { int num1,num2; for(num2=0;num2<=9;num2++) { for(num1=0;num1<=9;num1++) { cout<<num2<<""<<num1<<endl; } } return 0; }

//draws a Pyramid shape /*

* *** ***** */

#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; }

Potrebbero piacerti anche