Advertisement
Guest User

asd

a guest
Oct 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include "iostream"
  2. using namespace std;
  3.  
  4. int i,j,n;
  5. bool isValid(int n){
  6.     while( n != 0 ){
  7.         int x = n % 10;
  8.         if( x == 0 || x == 1 ) return false;
  9.         n /= 10;
  10.     }
  11.     return true;
  12. }
  13.  
  14. bool isEvenNumber(int n){
  15.     return !(n%2);
  16. }
  17.  
  18. void drawTriangle(int x){
  19.     for( i = 1 ; i <= x ; ++i ){
  20.         for( j = 1 ; j <= i ; ++j ) cout << j << " ";
  21.         cout << endl;
  22.     }
  23. }
  24.  
  25. void drawSquare(int x){
  26.     for( i = 1 ; i <= x ; ++i){
  27.         for( j = 1 ; j <= x ; ++j) cout << j << " ";
  28.         cout << endl;
  29.     }
  30. }
  31.  
  32. int main(int argc, char **argv){
  33.     while( true ){
  34.         cout << "Insert positive integer : ";
  35.         cin >> n;
  36.         if( !n ) continue;
  37.         if( isValid(n) ) break;
  38.     }
  39.  
  40.     while( n != 0 ){
  41.         int x = n % 10;
  42.         if( isEvenNumber(n) ) drawTriangle(x);
  43.         else drawSquare(x);
  44.         n /= 10;
  45.         cout << endl;
  46.     }
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement