Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- using namespace std;
- int i,j,n;
- bool isValid(int n){
- while( n != 0 ){
- int x = n % 10;
- if( x == 0 || x == 1 ) return false;
- n /= 10;
- }
- return true;
- }
- bool isEvenNumber(int n){
- return !(n%2);
- }
- void drawTriangle(int x){
- for( i = 1 ; i <= x ; ++i ){
- for( j = 1 ; j <= i ; ++j ) cout << j << " ";
- cout << endl;
- }
- }
- void drawSquare(int x){
- for( i = 1 ; i <= x ; ++i){
- for( j = 1 ; j <= x ; ++j) cout << j << " ";
- cout << endl;
- }
- }
- int main(int argc, char **argv){
- while( true ){
- cout << "Insert positive integer : ";
- cin >> n;
- if( !n ) continue;
- if( isValid(n) ) break;
- }
- while( n != 0 ){
- int x = n % 10;
- if( isEvenNumber(n) ) drawTriangle(x);
- else drawSquare(x);
- n /= 10;
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement