Flat Asterisk Pyramid
Part of the Fundamentals section of Coddy's R journey — lesson 76 of 78.
Challenge
EasyRead a single integer n from input and print a left-aligned asterisk pyramid with n rows.
Each row i (from 1 to n) should contain exactly i asterisks. Use the strrep() function to repeat the "*" character and cat() to print each row on a new line.
For example, if the input is:
5The output should be:
*
**
***
****
*****If the input is:
3The output should be:
*
**
***Try it yourself
# Read input
con <- file("stdin", "r")
n <- as.integer(suppressWarnings(readLines(con, n = 1)))
# TODO: Write your code below
# Use a loop to print n rows
# Each row i should contain i asterisks
# Use strrep() to repeat "*" and cat() to print each rowAll lessons in Fundamentals
4Operators Part 2
Logical Operators (AND, OR)Logical Operators Part 2 (NOT)Recap - Simple LogicVectorized Logic Part 1Vectorized Logic Part 22Variables and Data Types
Numeric Data TypeInteger Data TypeCharacter Data TypeLogical Data TypeChecking Data TypesNaming ConventionsMissing Values: NARecap - Variable Creation8Loops
For LoopWhile LoopBreakNext (Continue)Recap - FactorialSequence Generation (seq, :)Nested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsInteger Division and ModuloAssignment OperatorsRecap - Simple MathComparison Operators6Basic IO
Print OutputCat for OutputOutput With VariablesReading Input with readline()Type Conversion BasicsRecap - Age CalculatorRecap - True or False9Functions
Declaring a FunctionFunction ArgumentsReturn ValuesRecap - Sigma FunctionRecap - Validation FunctionDefault Parameter Values