Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- /**
- * Draws ASCII art triangle of given size with given char.
- *
- * @param size Size of triangle to be drawn
- * @param c Char to be used to draw a triangle.
- */
- void drawTriangle ( int size, char c )
- {
- for ( int i = 0; i < size; ++i )
- for ( int j = 0; j <= i; ++j )
- std::cout << c << ( j == i ? "\n" : " " );
- }
- /**
- * Program capable of drawing simple ASCII triangle.
- *
- * @return Returns 1 if wrong input is detected, 0 if everything ok.
- * @author Michael Hartman [email protected]
- */
- int main ( int argc, char ** argv )
- {
- std::cout << "Enter number: ";
- int num;
- if ( ! ( std::cin >> num ) || num < 0 )
- {
- std::cerr << "Bad input!" << std::endl;
- return 1;
- }
- drawTriangle ( num, '*' );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment